/** Tests that listeners are fired when a blog entry is unpublished. */ public void testListenersFiredWhenBlogEntryUnpublished() throws Exception { final StringBuffer buf = new StringBuffer("123"); blogEntry.setPublished(true); service.putBlogEntry(blogEntry); BlogEntryListener listener = new BlogEntryListener() { public void blogEntryAdded(BlogEntryEvent event) { fail(); } public void blogEntryRemoved(BlogEntryEvent event) { fail(); } public void blogEntryChanged(BlogEntryEvent event) { fail(); } public void blogEntryPublished(BlogEntryEvent event) { fail(); } public void blogEntryUnpublished(BlogEntryEvent event) { assertEquals(blogEntry, event.getSource()); buf.reverse(); } }; blog.getEventListenerList().addBlogEntryListener(listener); blogEntry.setPublished(false); service.putBlogEntry(blogEntry); assertEquals("321", buf.toString()); }
/** Tests that listeners are fired when a comment is added. */ public void testListenersFiredWhenCommentAdded() throws Exception { final StringBuffer buf = new StringBuffer("123"); final Comment comment = blogEntry.createComment( "title", "body", "author", "email", "website", "avatar", "127.0.0.1"); CommentListener listener = new CommentListener() { public void commentAdded(CommentEvent event) { assertEquals(comment, event.getSource()); buf.reverse(); } public void commentRemoved(CommentEvent event) { fail(); } public void commentApproved(CommentEvent event) { fail(); } public void commentRejected(CommentEvent event) { fail(); } }; blog.getEventListenerList().addCommentListener(listener); service.putBlogEntry(blogEntry); blogEntry.addComment(comment); service.putBlogEntry(blogEntry); assertEquals("321", buf.toString()); }
/** Tests that listeners are fired when a TrackBack is rejected. */ public void testListenersFiredWhenTrackBackRejected() throws Exception { final StringBuffer buf = new StringBuffer("123"); final TrackBack trackBack = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1"); blogEntry.addTrackBack(trackBack); trackBack.setPending(); service.putBlogEntry(blogEntry); TrackBackListener listener = new TrackBackListener() { public void trackBackAdded(TrackBackEvent event) {} public void trackBackRemoved(TrackBackEvent event) {} public void trackBackApproved(TrackBackEvent event) {} public void trackBackRejected(TrackBackEvent event) { assertEquals(trackBack, event.getSource()); buf.reverse(); } }; blog.getEventListenerList().addTrackBackListener(listener); trackBack.setRejected(); service.putBlogEntry(blogEntry); assertEquals("321", buf.toString()); }
@Factory("blogEntry9List") public void initBlogEntry9List() { log.info("initBlogEntry9List"); blogEntry9List = new HashMap<String, String>(); for (Object o : em.createQuery("from " + "BlogEntry").getResultList()) { BlogEntry p = (BlogEntry) o; blogEntry9List.put(p.getName(), p.getId().toString()); } }
protected void setUp() throws Exception { super.setUp(); service = new BlogService(); blogEntry = new BlogEntry(blog); blogEntry.setTitle("A title"); blogEntry.setBody("Some body"); blogEntry.setExcerpt("Some excerpt"); blogEntry.setAuthor("An author"); blogEntry.setDate(new Date()); }
/** Tests that comment listeners are fired when a blog entry is removed. */ public void testListenersFiredForCommentsWhenBlogEntryRemoved() throws Exception { final Comment comment1 = blogEntry.createComment( "title", "body", "author", "email", "website", "avatar", "127.0.0.1"); final Comment comment2 = blogEntry.createComment( "title", "body", "author", "email", "website", "avatar", "127.0.0.1"); final Comment comment3 = blogEntry.createComment( "title", "body", "author", "email", "website", "avatar", "127.0.0.1"); blogEntry.addComment(comment1); blogEntry.addComment(comment2); service.putBlogEntry(blogEntry); comment3.setParent(comment2); blogEntry.addComment(comment3); service.putBlogEntry(blogEntry); final List comments = new ArrayList(); CommentListener listener = new CommentListener() { public void commentAdded(CommentEvent event) { fail(); } public void commentRemoved(CommentEvent event) { comments.add(event.getSource()); } public void commentApproved(CommentEvent event) { fail(); } public void commentRejected(CommentEvent event) { fail(); } }; blog.getEventListenerList().addCommentListener(listener); service.removeBlogEntry(blogEntry); assertEquals(comment1, comments.get(0)); assertEquals(comment2, comments.get(1)); assertEquals(comment3, comments.get(2)); }
/** Tests that TrackBack listeners are fired when a blog entry is removed. */ public void testListenersFiredForTrackBacksWhenBlogEntryRemoved() throws Exception { final TrackBack trackBack1 = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1"); final TrackBack trackBack2 = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1"); final TrackBack trackBack3 = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1"); blogEntry.addTrackBack(trackBack1); blogEntry.addTrackBack(trackBack2); blogEntry.addTrackBack(trackBack3); service.putBlogEntry(blogEntry); final List trackBacks = new ArrayList(); TrackBackListener listener = new TrackBackListener() { public void trackBackAdded(TrackBackEvent event) { fail(); } public void trackBackRemoved(TrackBackEvent event) { trackBacks.add(event.getSource()); } public void trackBackApproved(TrackBackEvent event) { fail(); } public void trackBackRejected(TrackBackEvent event) { fail(); } }; blog.getEventListenerList().addTrackBackListener(listener); service.removeBlogEntry(blogEntry); assertEquals(trackBack1, trackBacks.get(0)); assertEquals(trackBack2, trackBacks.get(1)); assertEquals(trackBack3, trackBacks.get(2)); }
/** * Process the blog entries * * @param httpServletRequest Request * @param httpServletResponse Response * @param user {@link org.blojsom.blog.BlogUser} instance * @param context Context * @param entries Blog entries retrieved for the particular request * @return Modified set of blog entries * @throws BlojsomPluginException If there is an error processing the blog entries */ public BlogEntry[] process( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlogUser user, Map context, BlogEntry[] entries) throws BlojsomPluginException { if (!authenticateUser(httpServletRequest, httpServletResponse, context, user)) { httpServletRequest.setAttribute(PAGE_PARAM, ADMIN_LOGIN_PAGE); return entries; } String username = getUsernameFromSession(httpServletRequest, user.getBlog()); if (!checkPermission(user, null, username, EDIT_BLOG_ENTRIES_PERMISSION)) { httpServletRequest.setAttribute(PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); addOperationResultMessage( context, getAdminResource( FAILED_PERMISSION_EDIT_KEY, FAILED_PERMISSION_EDIT_KEY, user.getBlog().getBlogAdministrationLocale())); return entries; } String action = BlojsomUtils.getRequestValue(ACTION_PARAM, httpServletRequest); if (BlojsomUtils.checkNullOrBlank(action)) { _logger.debug("User did not request edit action"); httpServletRequest.setAttribute(PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); } else if (PAGE_ACTION.equals(action)) { _logger.debug("User requested edit blog entries page"); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); } else if (EDIT_BLOG_ENTRIES_ACTION.equals(action)) { _logger.debug("User requested edit blog entries list page"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(blogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(blogCategoryName)); Map fetchMap = new HashMap(); fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, category); fetchMap.put(BlojsomFetcher.FETCHER_NUM_POSTS_INTEGER, new Integer(-1)); try { entries = _fetcher.fetchEntries(fetchMap, user); if (entries != null) { _logger.debug( "Retrieved " + entries.length + " entries from category: " + blogCategoryName); Arrays.sort(entries, BlojsomUtils.FILE_TIME_COMPARATOR); } else { _logger.debug("No entries found in category: " + blogCategoryName); } } catch (BlojsomFetcherException e) { _logger.error(e); entries = new BlogEntry[0]; } context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST, entries); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRIES_LIST_PAGE); } else if (EDIT_BLOG_ENTRY_ACTION.equals(action)) { _logger.debug("User requested edit blog entry action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); _logger.debug("Blog entry id: " + blogEntryId); try { BlogEntry entry = BlojsomUtils.fetchEntry(_fetcher, user, blogCategoryName, blogEntryId); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); _blojsomConfiguration .getEventBroadcaster() .processEvent( new ProcessBlogEntryEvent( this, new Date(), entry, user, httpServletRequest, httpServletResponse, context)); } catch (BlojsomFetcherException e) { _logger.error(e); addOperationResultMessage( context, formatAdminResource( FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {blogEntryId})); entries = new BlogEntry[0]; } context.put( BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, BlojsomUtils.addSlashes(blogCategoryName)); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); } else if (UPDATE_BLOG_ENTRY_ACTION.equals(action)) { _logger.debug("User requested update blog entry action"); Blog blog = user.getBlog(); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String updatedBlogCategoryName = BlojsomUtils.getRequestValue(UPDATED_BLOG_CATEGORY_NAME, httpServletRequest); updatedBlogCategoryName = BlojsomUtils.normalize(updatedBlogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); String blogEntryDescription = BlojsomUtils.getRequestValue(BLOG_ENTRY_DESCRIPTION, httpServletRequest); String blogEntryTitle = BlojsomUtils.getRequestValue(BLOG_ENTRY_TITLE, httpServletRequest); if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)) { blogEntryDescription = BlojsomUtils.LINE_SEPARATOR + blogEntryDescription; } String allowComments = BlojsomUtils.getRequestValue(BLOG_METADATA_COMMENTS_DISABLED, httpServletRequest); String allowTrackbacks = BlojsomUtils.getRequestValue(BLOG_METADATA_TRACKBACKS_DISABLED, httpServletRequest); String blogTrackbackURLs = BlojsomUtils.getRequestValue(BLOG_TRACKBACK_URLS, httpServletRequest); String pingBlogURLS = BlojsomUtils.getRequestValue(PING_BLOG_URLS, httpServletRequest); String sendPingbacks = BlojsomUtils.getRequestValue( PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, httpServletRequest); _logger.debug("Blog entry id: " + blogEntryId); try { BlogEntry entryToUpdate = BlojsomUtils.fetchEntry(_fetcher, user, blogCategoryName, blogEntryId); entryToUpdate.setTitle(blogEntryTitle); entryToUpdate.setDescription(blogEntryDescription); boolean movingCategory = !blogCategoryName.equals(updatedBlogCategoryName); Map entryMetaData = entryToUpdate.getMetaData(); if (entryMetaData == null) { entryMetaData = new HashMap(); } if (!BlojsomUtils.checkNullOrBlank(allowComments)) { entryMetaData.put(BLOG_METADATA_COMMENTS_DISABLED, "y"); } else { entryMetaData.remove(BLOG_METADATA_COMMENTS_DISABLED); } if (!BlojsomUtils.checkNullOrBlank(allowTrackbacks)) { entryMetaData.put(BLOG_METADATA_TRACKBACKS_DISABLED, "y"); } else { entryMetaData.remove(BLOG_METADATA_TRACKBACKS_DISABLED); } if (BlojsomUtils.checkNullOrBlank(pingBlogURLS)) { entryMetaData.put(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA, "true"); } else { entryMetaData.remove(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA); } if (!BlojsomUtils.checkNullOrBlank(sendPingbacks)) { entryMetaData.put(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, "true"); } else { entryMetaData.remove(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS); } String entryPublishDateTime = httpServletRequest.getParameter(BLOG_ENTRY_PUBLISH_DATETIME); if (!BlojsomUtils.checkNullOrBlank(entryPublishDateTime)) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); try { Date publishDateTime = simpleDateFormat.parse(entryPublishDateTime); _logger.debug("Publishing blog entry at: " + publishDateTime.toString()); entryMetaData.put( BlojsomMetaDataConstants.BLOG_ENTRY_METADATA_TIMESTAMP, Long.toString(publishDateTime.getTime())); } catch (ParseException e) { _logger.error(e); } } entryToUpdate.setMetaData(entryMetaData); _blojsomConfiguration .getEventBroadcaster() .processEvent( new ProcessBlogEntryEvent( this, new Date(), entryToUpdate, user, httpServletRequest, httpServletResponse, context)); if (movingCategory) { _logger.debug("Moving entry from " + blogCategoryName + " to " + updatedBlogCategoryName); BlogEntry movedEntry = _fetcher.newBlogEntry(); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(updatedBlogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(updatedBlogCategoryName)); movedEntry.setTitle(blogEntryTitle); movedEntry.setCategory(updatedBlogCategoryName); movedEntry.setDescription(blogEntryDescription); movedEntry.setBlogCategory(category); movedEntry.setMetaData(entryMetaData); movedEntry.setComments(entryToUpdate.getComments()); movedEntry.setTrackbacks(entryToUpdate.getTrackbacks()); movedEntry.setPingbacks(entryToUpdate.getPingbacks()); movedEntry.save(user); _logger.debug("Moving " + entryToUpdate.getNumComments() + " comments"); List comments = entryToUpdate.getComments(); for (int i = 0; i < comments.size(); i++) { BlogComment blogComment = (BlogComment) comments.get(i); try { BlogComment movedComment = _fetcher.newBlogComment(); movedComment.setAuthor(blogComment.getAuthor()); movedComment.setAuthorEmail(blogComment.getAuthorEmail()); movedComment.setAuthorURL(blogComment.getAuthorURL()); movedComment.setBlogEntry(movedEntry); movedComment.setComment(blogComment.getComment()); movedComment.setMetaData(blogComment.getMetaData()); movedComment.setId(blogComment.getId()); movedComment.setCommentDateLong(blogComment.getCommentDateLong()); movedComment.save(user); blogComment.delete(user); } catch (BlojsomException e) { _logger.error(e); } } _logger.debug("Moving " + entryToUpdate.getNumTrackbacks() + " trackbacks"); List trackbacks = entryToUpdate.getTrackbacks(); for (int i = 0; i < trackbacks.size(); i++) { Trackback trackback = (Trackback) trackbacks.get(i); try { Trackback movedTrackback = _fetcher.newTrackback(); movedTrackback.setBlogEntry(movedEntry); movedTrackback.setBlogName(trackback.getBlogName()); movedTrackback.setExcerpt(trackback.getExcerpt()); movedTrackback.setId(trackback.getId()); movedTrackback.setMetaData(trackback.getMetaData()); movedTrackback.setTitle(trackback.getTitle()); movedTrackback.setUrl(trackback.getUrl()); movedTrackback.setTrackbackDateLong(trackback.getTrackbackDateLong()); movedTrackback.save(user); trackback.delete(user); } catch (BlojsomException e) { _logger.error(e); } } _logger.debug("Moving " + entryToUpdate.getNumPingbacks() + " pingbacks"); List pingbacks = entryToUpdate.getPingbacks(); for (int i = 0; i < pingbacks.size(); i++) { Pingback pingback = (Pingback) pingbacks.get(i); try { Pingback movedPingback = _fetcher.newPingback(); movedPingback.setBlogEntry(movedEntry); movedPingback.setBlogName(pingback.getBlogName()); movedPingback.setExcerpt(pingback.getExcerpt()); movedPingback.setId(pingback.getId()); movedPingback.setMetaData(pingback.getMetaData()); movedPingback.setTitle(pingback.getTitle()); movedPingback.setUrl(pingback.getUrl()); movedPingback.setTrackbackDateLong(pingback.getTrackbackDateLong()); movedPingback.save(user); pingback.delete(user); } catch (BlojsomException e) { _logger.error(e); } } movedEntry.load(user); entryToUpdate.delete(user); entryToUpdate = movedEntry; } else { entryToUpdate.save(user); } entryToUpdate.load(user); _logger.debug("Updated blog entry: " + entryToUpdate.getLink()); StringBuffer entryLink = new StringBuffer(); entryLink .append("<a href=\"") .append(user.getBlog().getBlogURL()) .append(BlojsomUtils.removeInitialSlash(entryToUpdate.getCategory())) .append("?") .append(PERMALINK_PARAM) .append("=") .append(entryToUpdate.getPermalink()) .append("\">") .append(entryToUpdate.getTitle()) .append("</a>"); addOperationResultMessage( context, formatAdminResource( UPDATED_BLOG_ENTRY_KEY, UPDATED_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {entryLink.toString()})); UpdatedBlogEntryEvent updateEvent = new UpdatedBlogEntryEvent(this, new Date(), entryToUpdate, user); _blojsomConfiguration.getEventBroadcaster().broadcastEvent(updateEvent); // Send trackback pings if (!BlojsomUtils.checkNullOrBlank(blogTrackbackURLs)) { sendTrackbackPings(blog, entryToUpdate, blogTrackbackURLs); } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entryToUpdate); if (movingCategory) { blogCategoryName = updatedBlogCategoryName; } blogCategoryName = BlojsomUtils.addSlashes(blogCategoryName); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); } catch (BlojsomFetcherException e) { _logger.error(e); addOperationResultMessage( context, formatAdminResource( FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {blogEntryId})); httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); entries = new BlogEntry[0]; } catch (BlojsomException e) { _logger.error(e); addOperationResultMessage( context, formatAdminResource( FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {blogEntryId})); entries = new BlogEntry[0]; httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); } } else if (DELETE_BLOG_ENTRY_ACTION.equals(action)) { _logger.debug("User requested delete blog entry action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); _logger.debug("Blog entry id: " + blogEntryId); try { BlogEntry entryToDelete = BlojsomUtils.fetchEntry(_fetcher, user, blogCategoryName, blogEntryId); String title = entryToDelete.getTitle(); entryToDelete.delete(user); addOperationResultMessage( context, formatAdminResource( DELETED_BLOG_ENTRY_KEY, DELETED_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {title})); DeletedBlogEntryEvent deleteEvent = new DeletedBlogEntryEvent(this, new Date(), entryToDelete, user); _blojsomConfiguration.getEventBroadcaster().broadcastEvent(deleteEvent); } catch (BlojsomFetcherException e) { _logger.error(e); addOperationResultMessage( context, formatAdminResource( FAILED_DELETE_BLOG_ENTRY_KEY, FAILED_DELETE_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {blogEntryId})); entries = new BlogEntry[0]; } catch (BlojsomException e) { _logger.error(e); addOperationResultMessage( context, formatAdminResource( FAILED_DELETE_BLOG_ENTRY_KEY, FAILED_DELETE_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {blogEntryId})); entries = new BlogEntry[0]; } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); } else if (NEW_BLOG_ENTRY_ACTION.equals(action)) { _logger.debug("User requested new blog entry action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); _blojsomConfiguration .getEventBroadcaster() .processEvent( new ProcessBlogEntryEvent( this, new Date(), null, user, httpServletRequest, httpServletResponse, context)); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); httpServletRequest.setAttribute(PAGE_PARAM, ADD_BLOG_ENTRY_PAGE); } else if (ADD_BLOG_ENTRY_ACTION.equals(action)) { _logger.debug("User requested add blog entry action"); Blog blog = user.getBlog(); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); if (!blogCategoryName.endsWith("/")) { blogCategoryName += "/"; } String blogEntryDescription = BlojsomUtils.getRequestValue(BLOG_ENTRY_DESCRIPTION, httpServletRequest); String blogEntryTitle = BlojsomUtils.getRequestValue(BLOG_ENTRY_TITLE, httpServletRequest); if (BlojsomUtils.checkNullOrBlank(blogEntryTitle) && BlojsomUtils.checkNullOrBlank(blogEntryDescription)) { httpServletRequest.setAttribute(PAGE_PARAM, ADD_BLOG_ENTRY_PAGE); _blojsomConfiguration .getEventBroadcaster() .processEvent( new ProcessBlogEntryEvent( this, new Date(), null, user, httpServletRequest, httpServletResponse, context)); addOperationResultMessage( context, getAdminResource( BLANK_ENTRY_KEY, BLANK_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale())); return entries; } if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)) { blogEntryDescription = BlojsomUtils.LINE_SEPARATOR + blogEntryDescription; } String allowComments = BlojsomUtils.getRequestValue(BLOG_METADATA_COMMENTS_DISABLED, httpServletRequest); String allowTrackbacks = BlojsomUtils.getRequestValue(BLOG_METADATA_TRACKBACKS_DISABLED, httpServletRequest); String blogTrackbackURLs = BlojsomUtils.getRequestValue(BLOG_TRACKBACK_URLS, httpServletRequest); String proposedBlogFilename = BlojsomUtils.getRequestValue(BLOG_ENTRY_PROPOSED_NAME, httpServletRequest); String pingBlogURLS = BlojsomUtils.getRequestValue(PING_BLOG_URLS, httpServletRequest); String sendPingbacks = BlojsomUtils.getRequestValue( PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, httpServletRequest); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(blogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(blogCategoryName)); BlogEntry entry; entry = _fetcher.newBlogEntry(); entry.setTitle(blogEntryTitle); entry.setCategory(blogCategoryName); entry.setDescription(blogEntryDescription); entry.setBlogCategory(category); Map entryMetaData = new HashMap(); username = (String) httpServletRequest .getSession() .getAttribute( user.getBlog().getBlogAdminURL() + "_" + BLOJSOM_ADMIN_PLUGIN_USERNAME_KEY); entryMetaData.put(BlojsomMetaDataConstants.BLOG_ENTRY_METADATA_AUTHOR, username); String entryPublishDateTime = httpServletRequest.getParameter(BLOG_ENTRY_PUBLISH_DATETIME); if (!BlojsomUtils.checkNullOrBlank(entryPublishDateTime)) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); try { Date publishDateTime = simpleDateFormat.parse(entryPublishDateTime); _logger.debug("Publishing blog entry at: " + publishDateTime.toString()); entryMetaData.put( BlojsomMetaDataConstants.BLOG_ENTRY_METADATA_TIMESTAMP, Long.toString(publishDateTime.getTime())); } catch (ParseException e) { _logger.error(e); entryMetaData.put( BlojsomMetaDataConstants.BLOG_ENTRY_METADATA_TIMESTAMP, Long.toString(new Date().getTime())); } } else { entryMetaData.put( BlojsomMetaDataConstants.BLOG_ENTRY_METADATA_TIMESTAMP, Long.toString(new Date().getTime())); } if (!BlojsomUtils.checkNullOrBlank(allowComments)) { entryMetaData.put(BLOG_METADATA_COMMENTS_DISABLED, "y"); } if (!BlojsomUtils.checkNullOrBlank(allowTrackbacks)) { entryMetaData.put(BLOG_METADATA_TRACKBACKS_DISABLED, "y"); } if (BlojsomUtils.checkNullOrBlank(pingBlogURLS)) { entryMetaData.put(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA, "true"); } if (!BlojsomUtils.checkNullOrBlank(sendPingbacks)) { entryMetaData.put(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, "true"); } entry.setMetaData(entryMetaData); try { _blojsomConfiguration .getEventBroadcaster() .processEvent( new ProcessBlogEntryEvent( this, new Date(), entry, user, httpServletRequest, httpServletResponse, context)); entry.save(user); entry.load(user); StringBuffer entryLink = new StringBuffer(); entry.setLink( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(entry.getCategory()) + "?" + PERMALINK_PARAM + "=" + entry.getPermalink()); entryLink .append("<a href=\"") .append(entry.getLink()) .append("\">") .append(entry.getTitle()) .append("</a>"); addOperationResultMessage( context, formatAdminResource( ADDED_BLOG_ENTRY_KEY, ADDED_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {entryLink.toString()})); AddBlogEntryEvent addEvent = new AddBlogEntryEvent(this, new Date(), entry, user); _blojsomConfiguration.getEventBroadcaster().broadcastEvent(addEvent); } catch (BlojsomException e) { _logger.error(e); addOperationResultMessage( context, formatAdminResource( FAILED_ADD_BLOG_ENTRY_KEY, FAILED_ADD_BLOG_ENTRY_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {blogCategoryName})); } // Send trackback pings if (!BlojsomUtils.checkNullOrBlank(blogTrackbackURLs)) { sendTrackbackPings(blog, entry, blogTrackbackURLs); } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_ACTION); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); } else if (DELETE_BLOG_COMMENTS.equals(action)) { _logger.debug("User requested delete blog comments action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); try { blogEntryId = URLDecoder.decode(blogEntryId, UTF8); } catch (UnsupportedEncodingException e) { _logger.error(e); } _logger.debug("Blog entry id: " + blogEntryId); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(blogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(blogCategoryName)); Map fetchMap = new HashMap(); fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, category); fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, blogEntryId); try { entries = _fetcher.fetchEntries(fetchMap, user); if (entries != null) { _logger.debug( "Retrieved " + entries.length + " entries from category: " + blogCategoryName); BlogEntry entryToUpdate = entries[0]; String[] blogCommentIDs = httpServletRequest.getParameterValues(BLOG_COMMENT_ID); if (blogCommentIDs != null && blogCommentIDs.length > 0) { for (int i = 0; i < blogCommentIDs.length; i++) { String blogCommentID = blogCommentIDs[i]; BlogComment[] blogComments = entryToUpdate.getCommentsAsArray(); for (int j = 0; j < blogComments.length; j++) { BlogComment blogComment = blogComments[j]; if (blogComment.getId().equals(blogCommentID)) { try { blogComment.delete(user); _blojsomConfiguration .getEventBroadcaster() .broadcastEvent( new CommentDeletedEvent(this, new Date(), blogComment, user)); } catch (BlojsomException e) { _logger.error(e); } } } } addOperationResultMessage( context, formatAdminResource( DELETED_COMMENTS_KEY, DELETED_COMMENTS_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {new Integer(blogCommentIDs.length)})); entries = _fetcher.fetchEntries(fetchMap, user); entryToUpdate = entries[0]; } context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entryToUpdate); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); } } catch (BlojsomFetcherException e) { _logger.error(e); } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); } else if (APPROVE_BLOG_COMMENTS.equals(action)) { _logger.debug("User requested approve blog comments action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); try { blogEntryId = URLDecoder.decode(blogEntryId, UTF8); } catch (UnsupportedEncodingException e) { _logger.error(e); } _logger.debug("Blog entry id: " + blogEntryId); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(blogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(blogCategoryName)); Map fetchMap = new HashMap(); fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, category); fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, blogEntryId); try { entries = _fetcher.fetchEntries(fetchMap, user); if (entries != null) { _logger.debug( "Retrieved " + entries.length + " entries from category: " + blogCategoryName); BlogEntry entryToUpdate = entries[0]; String[] blogCommentIDs = httpServletRequest.getParameterValues(BLOG_COMMENT_ID); if (blogCommentIDs != null && blogCommentIDs.length > 0) { for (int i = 0; i < blogCommentIDs.length; i++) { String blogCommentID = blogCommentIDs[i]; BlogComment[] blogComments = entryToUpdate.getCommentsAsArray(); for (int j = 0; j < blogComments.length; j++) { BlogComment blogComment = blogComments[j]; if (blogComment.getId().equals(blogCommentID)) { Map blogCommentMetaData = blogComment.getMetaData(); blogCommentMetaData.put( CommentModerationPlugin.BLOJSOM_COMMENT_MODERATION_PLUGIN_APPROVED, "true"); try { blogComment.save(user); _blojsomConfiguration .getEventBroadcaster() .broadcastEvent( new CommentApprovedEvent(this, new Date(), blogComment, user)); } catch (BlojsomException e) { _logger.error(e); } } } } addOperationResultMessage( context, formatAdminResource( APPROVED_COMMENTS_KEY, APPROVED_COMMENTS_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {new Integer(blogCommentIDs.length)})); entries = _fetcher.fetchEntries(fetchMap, user); entryToUpdate = entries[0]; } context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entryToUpdate); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); } } catch (BlojsomFetcherException e) { _logger.error(e); } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); } else if (DELETE_BLOG_TRACKBACKS.equals(action)) { _logger.debug("User requested delete blog trackbacks action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); try { blogEntryId = URLDecoder.decode(blogEntryId, UTF8); } catch (UnsupportedEncodingException e) { _logger.error(e); } _logger.debug("Blog entry id: " + blogEntryId); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(blogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(blogCategoryName)); Map fetchMap = new HashMap(); fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, category); fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, blogEntryId); try { entries = _fetcher.fetchEntries(fetchMap, user); if (entries != null) { _logger.debug( "Retrieved " + entries.length + " entries from category: " + blogCategoryName); BlogEntry entryToUpdate = entries[0]; String[] blogTrackbackIDs = httpServletRequest.getParameterValues(BLOG_TRACKBACK_ID); if (blogTrackbackIDs != null && blogTrackbackIDs.length > 0) { for (int i = 0; i < blogTrackbackIDs.length; i++) { String blogTrackbackID = blogTrackbackIDs[i]; Trackback[] trackbacks = entryToUpdate.getTrackbacksAsArray(); for (int j = 0; j < trackbacks.length; j++) { Trackback trackback = trackbacks[j]; if (trackback.getId().equals(blogTrackbackID)) { try { trackback.delete(user); _blojsomConfiguration .getEventBroadcaster() .broadcastEvent( new TrackbackDeletedEvent(this, new Date(), trackback, user)); } catch (BlojsomException e) { _logger.error(e); } } } } addOperationResultMessage( context, formatAdminResource( DELETED_TRACKBACKS_KEY, DELETED_TRACKBACKS_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {new Integer(blogTrackbackIDs.length)})); entries = _fetcher.fetchEntries(fetchMap, user); entryToUpdate = entries[0]; } context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entryToUpdate); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); } } catch (BlojsomFetcherException e) { _logger.error(e); } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); } else if (APPROVE_BLOG_TRACKBACKS.equals(action)) { _logger.debug("User requested approve blog trackbacks action"); String blogCategoryName = BlojsomUtils.getRequestValue(BLOG_CATEGORY_NAME, httpServletRequest); blogCategoryName = BlojsomUtils.normalize(blogCategoryName); String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); try { blogEntryId = URLDecoder.decode(blogEntryId, UTF8); } catch (UnsupportedEncodingException e) { _logger.error(e); } _logger.debug("Blog entry id: " + blogEntryId); BlogCategory category; category = _fetcher.newBlogCategory(); category.setCategory(blogCategoryName); category.setCategoryURL( user.getBlog().getBlogURL() + BlojsomUtils.removeInitialSlash(blogCategoryName)); Map fetchMap = new HashMap(); fetchMap.put(BlojsomFetcher.FETCHER_CATEGORY, category); fetchMap.put(BlojsomFetcher.FETCHER_PERMALINK, blogEntryId); try { entries = _fetcher.fetchEntries(fetchMap, user); if (entries != null) { _logger.debug( "Retrieved " + entries.length + " entries from category: " + blogCategoryName); BlogEntry entryToUpdate = entries[0]; String[] blogTrackbackIDs = httpServletRequest.getParameterValues(BLOG_TRACKBACK_ID); if (blogTrackbackIDs != null && blogTrackbackIDs.length > 0) { for (int i = 0; i < blogTrackbackIDs.length; i++) { String blogTrackbackID = blogTrackbackIDs[i]; Trackback[] trackbacks = entryToUpdate.getTrackbacksAsArray(); for (int j = 0; j < trackbacks.length; j++) { Trackback trackback = trackbacks[j]; if (trackback.getId().equals(blogTrackbackID)) { Map blogTrackbackMetaData = trackback.getMetaData(); blogTrackbackMetaData.put( TrackbackModerationPlugin.BLOJSOM_TRACKBACK_MODERATION_PLUGIN_APPROVED, "true"); try { trackback.save(user); _blojsomConfiguration .getEventBroadcaster() .broadcastEvent( new TrackbackApprovedEvent(this, new Date(), trackback, user)); } catch (BlojsomException e) { _logger.error(e); } } } } addOperationResultMessage( context, formatAdminResource( APPROVED_TRACKBACKS_KEY, APPROVED_TRACKBACKS_KEY, user.getBlog().getBlogAdministrationLocale(), new Object[] {new Integer(blogTrackbackIDs.length)})); entries = _fetcher.fetchEntries(fetchMap, user); entryToUpdate = entries[0]; } context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entryToUpdate); context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, blogCategoryName); } } catch (BlojsomFetcherException e) { _logger.error(e); } httpServletRequest.setAttribute(PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); } return entries; }
/** * Send trackback pings to a comma-separated list of trackback URLs * * @param blog Blog information * @param entry Blog entry * @param blogTrackbackURLs Trackback URLs */ protected void sendTrackbackPings(Blog blog, BlogEntry entry, String blogTrackbackURLs) { // Build the URL parameters for the trackback ping URL StringBuffer trackbackPingURLParameters = new StringBuffer(); try { trackbackPingURLParameters .append("&") .append(TrackbackPlugin.TRACKBACK_URL_PARAM) .append("=") .append(entry.getLink()); trackbackPingURLParameters .append("&") .append(TrackbackPlugin.TRACKBACK_TITLE_PARAM) .append("=") .append(URLEncoder.encode(entry.getTitle(), UTF8)); trackbackPingURLParameters .append("&") .append(TrackbackPlugin.TRACKBACK_BLOG_NAME_PARAM) .append("=") .append(URLEncoder.encode(blog.getBlogName(), UTF8)); String excerpt = entry.getDescription().replaceAll("<.*?>", ""); if (excerpt.length() > 255) { excerpt = excerpt.substring(0, 251); excerpt += "..."; } trackbackPingURLParameters .append("&") .append(TrackbackPlugin.TRACKBACK_EXCERPT_PARAM) .append("=") .append(URLEncoder.encode(excerpt, UTF8)); } catch (UnsupportedEncodingException e) { _logger.error(e); } String[] trackbackURLs = BlojsomUtils.parseDelimitedList(blogTrackbackURLs, WHITESPACE); if (trackbackURLs != null && trackbackURLs.length > 0) { for (int i = 0; i < trackbackURLs.length; i++) { String trackbackURL = trackbackURLs[i].trim(); StringBuffer trackbackPingURL = new StringBuffer(trackbackURL); _logger.debug( "Automatically sending trackback ping to URL: " + trackbackPingURL.toString()); try { URL trackbackUrl = new URL(trackbackPingURL.toString()); // Open a connection to the trackback URL and read its input HttpURLConnection trackbackUrlConnection = (HttpURLConnection) trackbackUrl.openConnection(); trackbackUrlConnection.setRequestMethod("POST"); trackbackUrlConnection.setRequestProperty("Content-Encoding", UTF8); trackbackUrlConnection.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded"); trackbackUrlConnection.setRequestProperty( "Content-Length", "" + trackbackPingURLParameters.length()); trackbackUrlConnection.setDoOutput(true); trackbackUrlConnection .getOutputStream() .write(trackbackPingURLParameters.toString().getBytes(UTF8)); trackbackUrlConnection.connect(); BufferedReader trackbackStatus = new BufferedReader(new InputStreamReader(trackbackUrlConnection.getInputStream())); String line; StringBuffer status = new StringBuffer(); while ((line = trackbackStatus.readLine()) != null) { status.append(line).append("\n"); } trackbackUrlConnection.disconnect(); _logger.debug("Trackback status for ping to " + trackbackURL + ": " + status.toString()); } catch (IOException e) { _logger.error(e); } } } }
public int compareTo(BlogEntry other) { return toString().toLowerCase().compareTo(other.toString().toLowerCase()); }