0001: /**
0002: * Copyright (c) 2003-2007, David A. Czarnecki
0003: * All rights reserved.
0004: *
0005: * Redistribution and use in source and binary forms, with or without
0006: * modification, are permitted provided that the following conditions are met:
0007: *
0008: * Redistributions of source code must retain the above copyright notice, this list of conditions and the
0009: * following disclaimer.
0010: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
0011: * following disclaimer in the documentation and/or other materials provided with the distribution.
0012: * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
0013: * endorse or promote products derived from this software without specific prior written permission.
0014: * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
0015: * without prior written permission of David A. Czarnecki.
0016: *
0017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
0018: * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
0019: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0020: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
0021: * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
0022: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
0026: * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
0027: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0028: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
0029: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0030: */package org.blojsom.plugin.admin;
0031:
0032: import org.apache.commons.logging.Log;
0033: import org.apache.commons.logging.LogFactory;
0034: import org.blojsom.blog.*;
0035: import org.blojsom.event.EventBroadcaster;
0036: import org.blojsom.fetcher.Fetcher;
0037: import org.blojsom.fetcher.FetcherException;
0038: import org.blojsom.plugin.PluginException;
0039: import org.blojsom.plugin.weblogsping.WeblogsPingPlugin;
0040: import org.blojsom.plugin.pingback.event.*;
0041: import org.blojsom.plugin.pingback.PingbackPlugin;
0042: import org.blojsom.plugin.trackback.event.*;
0043: import org.blojsom.plugin.trackback.TrackbackPlugin;
0044: import org.blojsom.plugin.common.ResponseConstants;
0045: import org.blojsom.plugin.comment.event.*;
0046: import org.blojsom.plugin.admin.event.EntryAddedEvent;
0047: import org.blojsom.plugin.admin.event.ProcessEntryEvent;
0048: import org.blojsom.plugin.admin.event.EntryDeletedEvent;
0049: import org.blojsom.plugin.admin.event.EntryUpdatedEvent;
0050: import org.blojsom.util.BlojsomMetaDataConstants;
0051: import org.blojsom.util.BlojsomUtils;
0052: import org.blojsom.util.BlojsomConstants;
0053:
0054: import javax.servlet.http.HttpServletRequest;
0055: import javax.servlet.http.HttpServletResponse;
0056: import java.text.ParseException;
0057: import java.text.SimpleDateFormat;
0058: import java.util.Date;
0059: import java.util.HashMap;
0060: import java.util.Map;
0061: import java.net.HttpURLConnection;
0062: import java.net.URLEncoder;
0063: import java.net.URL;
0064: import java.io.InputStreamReader;
0065: import java.io.BufferedReader;
0066: import java.io.IOException;
0067: import java.io.UnsupportedEncodingException;
0068:
0069: /**
0070: * EditBlogEntriesPlugin
0071: *
0072: * @author David Czarnecki
0073: * @version $Id: EditBlogEntriesPlugin.java,v 1.18 2007/01/17 02:35:05 czarneckid Exp $
0074: * @since blojsom 3.0
0075: */
0076: public class EditBlogEntriesPlugin extends BaseAdminPlugin {
0077:
0078: private Log _logger = LogFactory
0079: .getLog(EditBlogEntriesPlugin.class);
0080:
0081: // Pages
0082: private static final String EDIT_BLOG_ENTRIES_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-entries";
0083: private static final String EDIT_BLOG_ENTRIES_LIST_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-entries-list";
0084: private static final String EDIT_BLOG_ENTRY_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-entry";
0085: private static final String ADD_BLOG_ENTRY_PAGE = "/org/blojsom/plugin/admin/templates/admin-add-blog-entry";
0086: private static final String MANAGE_BLOG_ENTRIES_PAGE = "/org/blojsom/plugin/admin/templates/admin-manage-blog-entries";
0087:
0088: // Constants
0089: private static final String BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST = "BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST";
0090: private static final String BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY = "BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY";
0091: private static final String BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY = "BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY";
0092: private static final String BLOJSOM_PLUGIN_TOTAL_ENTRIES_PAGES = "BLOJSOM_PLUGIN_TOTAL_ENTRIES_PAGES";
0093: private static final String BLOJSOM_USER_OBJECT = "BLOJSOM_USER_OBJECT";
0094:
0095: // Localization constants
0096: private static final String FAILED_PERMISSION_EDIT_KEY = "failed.permission.edit.text";
0097: private static final String FAILED_RETRIEVE_BLOG_ENTRY_KEY = "failed.retrieve.entry.text";
0098: private static final String FAILED_DELETE_BLOG_ENTRY_KEY = "failed.delete.entry.text";
0099: private static final String FAILED_ADD_BLOG_ENTRY_KEY = "failed.add.entry.text";
0100: private static final String UPDATED_BLOG_ENTRY_KEY = "updated.blog.entry.text";
0101: private static final String DELETED_BLOG_ENTRY_KEY = "deleted.blog.entry.text";
0102: private static final String ADDED_BLOG_ENTRY_KEY = "added.blog.entry.text";
0103: private static final String DELETED_COMMENTS_KEY = "deleted.comments.text";
0104: private static final String APPROVED_COMMENTS_KEY = "approved.comments.text";
0105: private static final String DELETED_TRACKBACKS_KEY = "deleted.trackbacks.text";
0106: private static final String APPROVED_TRACKBACKS_KEY = "approved.trackbacks.text";
0107: private static final String APPROVED_PINGBACKS_KEY = "approved.pingbacks.text";
0108: private static final String DELETED_PINGBACKS_KEY = "deleted.pingbacks.text";
0109: private static final String BLANK_ENTRY_KEY = "blank.entry.text";
0110: private static final String INVALID_CATEGORYID_KEY = "invalid.categoryid.text";
0111:
0112: // Actions
0113: private static final String EDIT_BLOG_ENTRIES_ACTION = "edit-blog-entries";
0114: private static final String EDIT_BLOG_ENTRY_ACTION = "edit-blog-entry";
0115: private static final String UPDATE_BLOG_ENTRY_ACTION = "update-blog-entry";
0116: private static final String DELETE_BLOG_ENTRY_ACTION = "delete-blog-entry";
0117: private static final String NEW_BLOG_ENTRY_ACTION = "new-blog-entry";
0118: private static final String ADD_BLOG_ENTRY_ACTION = "add-blog-entry";
0119: private static final String DELETE_BLOG_COMMENTS = "delete-blog-comments";
0120: private static final String DELETE_BLOG_TRACKBACKS = "delete-blog-trackbacks";
0121: private static final String DELETE_BLOG_PINGBACKS = "delete-blog-pingbacks";
0122: private static final String APPROVE_BLOG_COMMENTS = "approve-blog-comments";
0123: private static final String APPROVE_BLOG_TRACKBACKS = "approve-blog-trackbacks";
0124: private static final String APPROVE_BLOG_PINGBACKS = "approve-blog-pingbacks";
0125: private static final String EDIT_ENTRIES_LIST = "edit-entries-list";
0126: private static final String DELETE_BLOG_ENTRY_LIST = "delete-blog-entry-list";
0127:
0128: // AJAX actions
0129: private static final String AJAX_DELETE_RESPONSE = "ajax-delete-response";
0130: private static final String AJAX_APPROVE_RESPONSE = "ajax-approve-response";
0131: private static final String AJAX_UNAPPROVE_RESPONSE = "ajax-unapprove-response";
0132: private static final String AJAX_MARK_SPAM_RESPONSE = "ajax-mark-spam-response";
0133: private static final String AJAX_UNMARK_SPAM_RESPONSE = "ajax-unmark-spam-response";
0134:
0135: // Form elements
0136: private static final String BLOG_CATEGORY_ID = "blog-category-id";
0137: private static final String BLOG_ENTRY_ID = "blog-entry-id";
0138: private static final String BLOG_ENTRY_TITLE = "blog-entry-title";
0139: private static final String BLOG_ENTRY_DESCRIPTION = "blog-entry-description";
0140: private static final String BLOG_COMMENT_ID = "blog-comment-id";
0141: private static final String BLOG_TRACKBACK_ID = "blog-trackback-id";
0142: private static final String BLOG_PINGBACK_ID = "blog-pingback-id";
0143: private static final String BLOG_ENTRY_PUBLISH_DATETIME = "blog-entry-publish-datetime";
0144: private static final String BLOG_TRACKBACK_URLS = "blog-trackback-urls";
0145: private static final String POST_SLUG = "post-slug";
0146: private static final String PING_BLOG_URLS = "ping-blog-urls";
0147: private static final String RESPONSE_TYPE = "response-type";
0148: private static final String RESPONSE_ID = "response-id";
0149: private static final String STATUS = "status";
0150: private static final String QUERY = "query";
0151:
0152: // Permissions
0153: private static final String EDIT_BLOG_ENTRIES_PERMISSION = "edit_blog_entries_permission";
0154:
0155: private Fetcher _fetcher;
0156: private EventBroadcaster _eventBroadcaster;
0157:
0158: /**
0159: * Default constructor.
0160: */
0161: public EditBlogEntriesPlugin() {
0162: }
0163:
0164: /**
0165: * Set the {@link Fetcher}
0166: *
0167: * @param fetcher {@link Fetcher}
0168: */
0169: public void setFetcher(Fetcher fetcher) {
0170: _fetcher = fetcher;
0171: }
0172:
0173: /**
0174: * Set the {@link EventBroadcaster}
0175: *
0176: * @param eventBroadcaster {@link EventBroadcaster}
0177: */
0178: public void setEventBroadcaster(EventBroadcaster eventBroadcaster) {
0179: _eventBroadcaster = eventBroadcaster;
0180: }
0181:
0182: /**
0183: * Delete a blog entry
0184: * @param httpServletRequest Request
0185: * @param blog {@link Blog}
0186: * @param context Context
0187: * @return <code>true</code> if the entry was deleted, <code>false</code> otherwise
0188: */
0189: protected boolean deleteBlogEntry(
0190: HttpServletRequest httpServletRequest, Blog blog,
0191: Map context) {
0192: String blogEntryId = BlojsomUtils.getRequestValue(
0193: BLOG_ENTRY_ID, httpServletRequest);
0194: Integer entryId;
0195: try {
0196: entryId = Integer.valueOf(blogEntryId);
0197: } catch (NumberFormatException e) {
0198: addOperationResultMessage(context, formatAdminResource(
0199: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
0200: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
0201: .getBlogAdministrationLocale(),
0202: new Object[] { blogEntryId }));
0203: httpServletRequest.setAttribute(
0204: BlojsomConstants.PAGE_PARAM,
0205: ADMIN_ADMINISTRATION_PAGE);
0206:
0207: return false;
0208: }
0209:
0210: try {
0211: Entry entryToDelete = _fetcher.newEntry();
0212: entryToDelete.setId(entryId);
0213:
0214: _fetcher.loadEntry(blog, entryToDelete);
0215: String title = entryToDelete.getTitle();
0216: _fetcher.deleteEntry(blog, entryToDelete);
0217:
0218: addOperationResultMessage(context, formatAdminResource(
0219: DELETED_BLOG_ENTRY_KEY, DELETED_BLOG_ENTRY_KEY,
0220: blog.getBlogAdministrationLocale(),
0221: new Object[] { title }));
0222:
0223: EntryDeletedEvent deleteEvent = new EntryDeletedEvent(this ,
0224: new Date(), entryToDelete, blog);
0225: _eventBroadcaster.broadcastEvent(deleteEvent);
0226: } catch (FetcherException e) {
0227: if (_logger.isErrorEnabled()) {
0228: _logger.error(e);
0229: }
0230:
0231: addOperationResultMessage(context, formatAdminResource(
0232: FAILED_DELETE_BLOG_ENTRY_KEY,
0233: FAILED_DELETE_BLOG_ENTRY_KEY, blog
0234: .getBlogAdministrationLocale(),
0235: new Object[] { blogEntryId }));
0236: return false;
0237: }
0238:
0239: return true;
0240: }
0241:
0242: /**
0243: * Process the blog entries
0244: *
0245: * @param httpServletRequest Request
0246: * @param httpServletResponse Response
0247: * @param blog {@link Blog} instance
0248: * @param context Context
0249: * @param entries Blog entries retrieved for the particular request
0250: * @return Modified set of blog entries
0251: * @throws PluginException If there is an error processing the blog entries
0252: */
0253: public Entry[] process(HttpServletRequest httpServletRequest,
0254: HttpServletResponse httpServletResponse, Blog blog,
0255: Map context, Entry[] entries) throws PluginException {
0256: if (!authenticateUser(httpServletRequest, httpServletResponse,
0257: context, blog)) {
0258: httpServletRequest.setAttribute(
0259: BlojsomConstants.PAGE_PARAM, ADMIN_LOGIN_PAGE);
0260:
0261: return entries;
0262: }
0263:
0264: String username = getUsernameFromSession(httpServletRequest,
0265: blog);
0266: if (!checkPermission(blog, null, username,
0267: EDIT_BLOG_ENTRIES_PERMISSION)) {
0268: httpServletRequest.setAttribute(
0269: BlojsomConstants.PAGE_PARAM,
0270: ADMIN_ADMINISTRATION_PAGE);
0271: addOperationResultMessage(context, getAdminResource(
0272: FAILED_PERMISSION_EDIT_KEY,
0273: FAILED_PERMISSION_EDIT_KEY, blog
0274: .getBlogAdministrationLocale()));
0275:
0276: return entries;
0277: }
0278:
0279: try {
0280: context.put(BLOJSOM_USER_OBJECT, _fetcher.loadUser(blog,
0281: username));
0282: } catch (FetcherException e) {
0283: if (_logger.isErrorEnabled()) {
0284: _logger.error(e);
0285: }
0286: }
0287:
0288: String action = BlojsomUtils.getRequestValue(ACTION_PARAM,
0289: httpServletRequest);
0290: String subAction = BlojsomUtils.getRequestValue(
0291: SUBACTION_PARAM, httpServletRequest);
0292:
0293: if (BlojsomUtils.checkNullOrBlank(action)) {
0294: if (_logger.isDebugEnabled()) {
0295: _logger.debug("User did not request edit action");
0296: }
0297: httpServletRequest.setAttribute(
0298: BlojsomConstants.PAGE_PARAM,
0299: ADMIN_ADMINISTRATION_PAGE);
0300: } else if (PAGE_ACTION.equals(action)) {
0301: if (_logger.isDebugEnabled()) {
0302: _logger.debug("User requested edit blog entries page");
0303: }
0304:
0305: httpServletRequest
0306: .setAttribute(BlojsomConstants.PAGE_PARAM,
0307: EDIT_BLOG_ENTRIES_PAGE);
0308: } else if (EDIT_BLOG_ENTRIES_ACTION.equals(action)) {
0309: if (_logger.isDebugEnabled()) {
0310: _logger
0311: .debug("User requested edit blog entries list page");
0312: }
0313:
0314: String blogCategoryId = BlojsomUtils.getRequestValue(
0315: BLOG_CATEGORY_ID, httpServletRequest);
0316: Integer categoryId;
0317: Category category = null;
0318: try {
0319: categoryId = Integer.valueOf(blogCategoryId);
0320: } catch (NumberFormatException e) {
0321: addOperationResultMessage(context, formatAdminResource(
0322: INVALID_CATEGORYID_KEY, INVALID_CATEGORYID_KEY,
0323: blog.getBlogAdministrationLocale(),
0324: new Object[] { blogCategoryId }));
0325: httpServletRequest.setAttribute(
0326: BlojsomConstants.PAGE_PARAM,
0327: ADMIN_ADMINISTRATION_PAGE);
0328:
0329: return entries;
0330: }
0331:
0332: try {
0333: entries = _fetcher.loadAllEntriesForCategory(blog,
0334: categoryId);
0335: category = _fetcher.loadCategory(blog, categoryId);
0336: } catch (FetcherException e) {
0337: if (_logger.isErrorEnabled()) {
0338: _logger.error(e);
0339: }
0340:
0341: entries = new Entry[0];
0342: }
0343:
0344: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY,
0345: category);
0346: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST, entries);
0347:
0348: httpServletRequest.setAttribute(
0349: BlojsomConstants.PAGE_PARAM,
0350: EDIT_BLOG_ENTRIES_LIST_PAGE);
0351: } else if (EDIT_BLOG_ENTRY_ACTION.equals(action)) {
0352: if (_logger.isDebugEnabled()) {
0353: _logger.debug("User requested edit blog entry action");
0354: }
0355:
0356: String blogEntryId = BlojsomUtils.getRequestValue(
0357: BLOG_ENTRY_ID, httpServletRequest);
0358: Integer entryId;
0359: try {
0360: entryId = Integer.valueOf(blogEntryId);
0361: } catch (NumberFormatException e) {
0362: addOperationResultMessage(context, formatAdminResource(
0363: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
0364: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
0365: .getBlogAdministrationLocale(),
0366: new Object[] { blogEntryId }));
0367: httpServletRequest.setAttribute(
0368: BlojsomConstants.PAGE_PARAM,
0369: ADMIN_ADMINISTRATION_PAGE);
0370:
0371: return entries;
0372: }
0373:
0374: try {
0375: Entry entry = _fetcher.newEntry();
0376: entry.setId(entryId);
0377: _fetcher.loadEntry(blog, entry);
0378: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
0379: entry);
0380:
0381: _eventBroadcaster.processEvent(new ProcessEntryEvent(
0382: this , new Date(), entry, blog,
0383: httpServletRequest, httpServletResponse,
0384: context));
0385: } catch (FetcherException e) {
0386: if (_logger.isErrorEnabled()) {
0387: _logger.error(e);
0388: }
0389:
0390: addOperationResultMessage(context, formatAdminResource(
0391: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
0392: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
0393: .getBlogAdministrationLocale(),
0394: new Object[] { blogEntryId }));
0395: httpServletRequest.setAttribute(
0396: BlojsomConstants.PAGE_PARAM,
0397: ADMIN_ADMINISTRATION_PAGE);
0398:
0399: return entries;
0400: }
0401:
0402: httpServletRequest.setAttribute(
0403: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
0404: } else if (UPDATE_BLOG_ENTRY_ACTION.equals(action)) {
0405: if (_logger.isDebugEnabled()) {
0406: _logger
0407: .debug("User requested update blog entry action");
0408: }
0409:
0410: String blogEntryId = BlojsomUtils.getRequestValue(
0411: BLOG_ENTRY_ID, httpServletRequest);
0412: Integer entryId;
0413: try {
0414: entryId = Integer.valueOf(blogEntryId);
0415: } catch (NumberFormatException e) {
0416: addOperationResultMessage(context, formatAdminResource(
0417: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
0418: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
0419: .getBlogAdministrationLocale(),
0420: new Object[] { blogEntryId }));
0421: httpServletRequest.setAttribute(
0422: BlojsomConstants.PAGE_PARAM,
0423: ADMIN_ADMINISTRATION_PAGE);
0424:
0425: return entries;
0426: }
0427:
0428: String blogCategoryId = BlojsomUtils.getRequestValue(
0429: BLOG_CATEGORY_ID, httpServletRequest);
0430: Integer categoryId;
0431: try {
0432: categoryId = Integer.valueOf(blogCategoryId);
0433: } catch (NumberFormatException e) {
0434: addOperationResultMessage(context, formatAdminResource(
0435: INVALID_CATEGORYID_KEY, INVALID_CATEGORYID_KEY,
0436: blog.getBlogAdministrationLocale(),
0437: new Object[] { blogCategoryId }));
0438: httpServletRequest.setAttribute(
0439: BlojsomConstants.PAGE_PARAM,
0440: ADMIN_ADMINISTRATION_PAGE);
0441:
0442: return entries;
0443: }
0444:
0445: String blogEntryDescription = BlojsomUtils.getRequestValue(
0446: BLOG_ENTRY_DESCRIPTION, httpServletRequest);
0447: String blogEntryTitle = BlojsomUtils.getRequestValue(
0448: BLOG_ENTRY_TITLE, httpServletRequest);
0449: if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)) {
0450: blogEntryDescription = BlojsomUtils.LINE_SEPARATOR
0451: + blogEntryDescription;
0452: }
0453:
0454: String allowComments = BlojsomUtils
0455: .getRequestValue(
0456: BlojsomMetaDataConstants.BLOG_METADATA_COMMENTS_DISABLED,
0457: httpServletRequest);
0458: String allowTrackbacks = BlojsomUtils
0459: .getRequestValue(
0460: BlojsomMetaDataConstants.BLOG_METADATA_TRACKBACKS_DISABLED,
0461: httpServletRequest);
0462: String allowPingbacks = BlojsomUtils
0463: .getRequestValue(
0464: BlojsomMetaDataConstants.BLOG_METADATA_PINGBACKS_DISABLED,
0465: httpServletRequest);
0466: String blogTrackbackURLs = BlojsomUtils.getRequestValue(
0467: BLOG_TRACKBACK_URLS, httpServletRequest);
0468: String pingBlogURLS = BlojsomUtils.getRequestValue(
0469: PING_BLOG_URLS, httpServletRequest);
0470: String sendPingbacks = BlojsomUtils
0471: .getRequestValue(
0472: PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS,
0473: httpServletRequest);
0474: String status = BlojsomUtils.getRequestValue(STATUS,
0475: httpServletRequest);
0476:
0477: try {
0478: Entry entryToUpdate = _fetcher.newEntry();
0479: entryToUpdate.setId(entryId);
0480: _fetcher.loadEntry(blog, entryToUpdate);
0481:
0482: entryToUpdate.setTitle(blogEntryTitle);
0483: entryToUpdate.setDescription(blogEntryDescription);
0484: entryToUpdate.setBlogCategoryId(categoryId);
0485:
0486: Map entryMetaData = entryToUpdate.getMetaData();
0487: if (entryMetaData == null) {
0488: entryMetaData = new HashMap();
0489: }
0490:
0491: if (!BlojsomUtils.checkNullOrBlank(allowComments)) {
0492: entryToUpdate.setAllowComments(new Integer(0));
0493: } else {
0494: entryToUpdate.setAllowComments(new Integer(1));
0495: }
0496:
0497: if (!BlojsomUtils.checkNullOrBlank(allowTrackbacks)) {
0498: entryToUpdate.setAllowTrackbacks(new Integer(0));
0499: } else {
0500: entryToUpdate.setAllowTrackbacks(new Integer(1));
0501: }
0502:
0503: if (!BlojsomUtils.checkNullOrBlank(allowPingbacks)) {
0504: entryToUpdate.setAllowPingbacks(new Integer(0));
0505: } else {
0506: entryToUpdate.setAllowPingbacks(new Integer(1));
0507: }
0508:
0509: if (BlojsomUtils.checkNullOrBlank(pingBlogURLS)) {
0510: entryMetaData.put(
0511: WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA,
0512: "true");
0513: } else {
0514: entryMetaData
0515: .remove(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA);
0516: }
0517:
0518: if (!BlojsomUtils.checkNullOrBlank(sendPingbacks)) {
0519: entryMetaData
0520: .put(
0521: PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS,
0522: "true");
0523: } else {
0524: entryMetaData
0525: .remove(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS);
0526: }
0527:
0528: String entryPublishDateTime = httpServletRequest
0529: .getParameter(BLOG_ENTRY_PUBLISH_DATETIME);
0530: if (!BlojsomUtils
0531: .checkNullOrBlank(entryPublishDateTime)) {
0532: SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
0533: "MM/dd/yyyy HH:mm:ss");
0534: try {
0535: Date publishDateTime = simpleDateFormat
0536: .parse(entryPublishDateTime);
0537: entryToUpdate.setDate(publishDateTime);
0538: entryToUpdate.setModifiedDate(publishDateTime);
0539: } catch (ParseException e) {
0540: }
0541: } else {
0542: entryToUpdate.setModifiedDate(new Date());
0543: }
0544:
0545: if (BlojsomUtils.checkNullOrBlank(status)) {
0546: status = BlojsomMetaDataConstants.DRAFT_STATUS;
0547: }
0548:
0549: entryToUpdate.setStatus(status);
0550: entryToUpdate.setMetaData(entryMetaData);
0551:
0552: _eventBroadcaster.processEvent(new ProcessEntryEvent(
0553: this , new Date(), entryToUpdate, blog,
0554: httpServletRequest, httpServletResponse,
0555: context));
0556:
0557: _fetcher.saveEntry(blog, entryToUpdate);
0558: _fetcher.loadEntry(blog, entryToUpdate);
0559:
0560: if (_logger.isDebugEnabled()) {
0561: _logger.debug("Updated blog entry: "
0562: + entryToUpdate.getId());
0563: }
0564:
0565: StringBuffer entryLink = new StringBuffer();
0566: entryLink.append("<a href=\"")
0567: .append(blog.getBlogURL()).append(
0568: entryToUpdate.getBlogCategory()
0569: .getName()).append(
0570: entryToUpdate.getPostSlug()).append(
0571: "\">").append(
0572: entryToUpdate.getEscapedTitle())
0573: .append("</a>");
0574: addOperationResultMessage(context, formatAdminResource(
0575: UPDATED_BLOG_ENTRY_KEY, UPDATED_BLOG_ENTRY_KEY,
0576: blog.getBlogAdministrationLocale(),
0577: new Object[] { entryLink.toString() }));
0578:
0579: EntryUpdatedEvent updateEvent = new EntryUpdatedEvent(
0580: this , new Date(), entryToUpdate, blog);
0581: _eventBroadcaster.broadcastEvent(updateEvent);
0582:
0583: // Send trackback pings
0584: if (!BlojsomUtils.checkNullOrBlank(blogTrackbackURLs)) {
0585: sendTrackbackPings(blog, entryToUpdate,
0586: blogTrackbackURLs);
0587: }
0588:
0589: httpServletRequest.setAttribute(
0590: BlojsomConstants.PAGE_PARAM,
0591: EDIT_BLOG_ENTRY_PAGE);
0592: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
0593: entryToUpdate);
0594: } catch (FetcherException e) {
0595: if (_logger.isErrorEnabled()) {
0596: _logger.error(e);
0597: }
0598:
0599: addOperationResultMessage(context, formatAdminResource(
0600: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
0601: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
0602: .getBlogAdministrationLocale(),
0603: new Object[] { blogEntryId }));
0604: httpServletRequest.setAttribute(
0605: BlojsomConstants.PAGE_PARAM,
0606: EDIT_BLOG_ENTRIES_PAGE);
0607: entries = new Entry[0];
0608: }
0609: } else if (DELETE_BLOG_ENTRY_ACTION.equals(action)) {
0610: if (_logger.isDebugEnabled()) {
0611: _logger
0612: .debug("User requested delete blog entry action");
0613: }
0614:
0615: String blogEntryId = BlojsomUtils.getRequestValue(
0616: BLOG_ENTRY_ID, httpServletRequest);
0617: Integer entryId;
0618: try {
0619: entryId = Integer.valueOf(blogEntryId);
0620: } catch (NumberFormatException e) {
0621: addOperationResultMessage(context, formatAdminResource(
0622: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
0623: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
0624: .getBlogAdministrationLocale(),
0625: new Object[] { blogEntryId }));
0626: httpServletRequest.setAttribute(
0627: BlojsomConstants.PAGE_PARAM,
0628: ADMIN_ADMINISTRATION_PAGE);
0629:
0630: return entries;
0631: }
0632:
0633: try {
0634: Entry entryToDelete = _fetcher.newEntry();
0635: entryToDelete.setId(entryId);
0636:
0637: _fetcher.loadEntry(blog, entryToDelete);
0638: String title = entryToDelete.getTitle();
0639: _fetcher.deleteEntry(blog, entryToDelete);
0640:
0641: addOperationResultMessage(context, formatAdminResource(
0642: DELETED_BLOG_ENTRY_KEY, DELETED_BLOG_ENTRY_KEY,
0643: blog.getBlogAdministrationLocale(),
0644: new Object[] { title }));
0645:
0646: EntryDeletedEvent deleteEvent = new EntryDeletedEvent(
0647: this , new Date(), entryToDelete, blog);
0648: _eventBroadcaster.broadcastEvent(deleteEvent);
0649: } catch (FetcherException e) {
0650: if (_logger.isErrorEnabled()) {
0651: _logger.error(e);
0652: }
0653:
0654: addOperationResultMessage(context, formatAdminResource(
0655: FAILED_DELETE_BLOG_ENTRY_KEY,
0656: FAILED_DELETE_BLOG_ENTRY_KEY, blog
0657: .getBlogAdministrationLocale(),
0658: new Object[] { blogEntryId }));
0659: entries = new Entry[0];
0660: }
0661:
0662: httpServletRequest
0663: .setAttribute(BlojsomConstants.PAGE_PARAM,
0664: EDIT_BLOG_ENTRIES_PAGE);
0665: } else if (NEW_BLOG_ENTRY_ACTION.equals(action)) {
0666: if (_logger.isDebugEnabled()) {
0667: _logger.debug("User requested new blog entry action");
0668: }
0669:
0670: _eventBroadcaster.processEvent(new ProcessEntryEvent(this ,
0671: new Date(), null, blog, httpServletRequest,
0672: httpServletResponse, context));
0673:
0674: httpServletRequest.setAttribute(
0675: BlojsomConstants.PAGE_PARAM, ADD_BLOG_ENTRY_PAGE);
0676: } else if (ADD_BLOG_ENTRY_ACTION.equals(action)) {
0677: if (_logger.isDebugEnabled()) {
0678: _logger.debug("User requested add blog entry action");
0679: }
0680:
0681: String blogCategoryId = BlojsomUtils.getRequestValue(
0682: BLOG_CATEGORY_ID, httpServletRequest);
0683:
0684: // Create a category for the blog if one doesn't exist
0685: if (BlojsomUtils.checkNullOrBlank(blogCategoryId)) {
0686: Category category = _fetcher.newCategory();
0687: category.setBlogId(blog.getId());
0688: category.setDescription("Uncategorized");
0689: category.setName("/uncategorized/");
0690: category.setParentCategoryId(null);
0691:
0692: try {
0693: _fetcher.saveCategory(blog, category);
0694: blogCategoryId = category.getId().toString();
0695: } catch (FetcherException e) {
0696: if (_logger.isErrorEnabled()) {
0697: _logger.error(e);
0698: }
0699:
0700: addOperationResultMessage(context,
0701: formatAdminResource(
0702: FAILED_ADD_BLOG_ENTRY_KEY,
0703: FAILED_ADD_BLOG_ENTRY_KEY,
0704: blog.getBlogAdministrationLocale(),
0705: new Object[] { blogCategoryId }));
0706: httpServletRequest.setAttribute(
0707: BlojsomConstants.PAGE_PARAM,
0708: ADMIN_ADMINISTRATION_PAGE);
0709:
0710: return entries;
0711: }
0712: }
0713:
0714: Integer categoryId;
0715: try {
0716: categoryId = Integer.valueOf(blogCategoryId);
0717: } catch (NumberFormatException e) {
0718: addOperationResultMessage(context, formatAdminResource(
0719: INVALID_CATEGORYID_KEY, INVALID_CATEGORYID_KEY,
0720: blog.getBlogAdministrationLocale(),
0721: new Object[] { blogCategoryId }));
0722: httpServletRequest.setAttribute(
0723: BlojsomConstants.PAGE_PARAM,
0724: ADMIN_ADMINISTRATION_PAGE);
0725:
0726: return entries;
0727: }
0728:
0729: String blogEntryDescription = BlojsomUtils.getRequestValue(
0730: BLOG_ENTRY_DESCRIPTION, httpServletRequest);
0731: String blogEntryTitle = BlojsomUtils.getRequestValue(
0732: BLOG_ENTRY_TITLE, httpServletRequest);
0733:
0734: if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)
0735: && BlojsomUtils
0736: .checkNullOrBlank(blogEntryDescription)) {
0737: httpServletRequest.setAttribute(
0738: BlojsomConstants.PAGE_PARAM,
0739: ADD_BLOG_ENTRY_PAGE);
0740: _eventBroadcaster.processEvent(new ProcessEntryEvent(
0741: this , new Date(), null, blog,
0742: httpServletRequest, httpServletResponse,
0743: context));
0744:
0745: addOperationResultMessage(context, getAdminResource(
0746: BLANK_ENTRY_KEY, BLANK_ENTRY_KEY, blog
0747: .getBlogAdministrationLocale()));
0748:
0749: return entries;
0750: }
0751:
0752: if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)) {
0753: blogEntryDescription = BlojsomUtils.LINE_SEPARATOR
0754: + blogEntryDescription;
0755: }
0756:
0757: String allowComments = BlojsomUtils
0758: .getRequestValue(
0759: BlojsomMetaDataConstants.BLOG_METADATA_COMMENTS_DISABLED,
0760: httpServletRequest);
0761: String allowTrackbacks = BlojsomUtils
0762: .getRequestValue(
0763: BlojsomMetaDataConstants.BLOG_METADATA_TRACKBACKS_DISABLED,
0764: httpServletRequest);
0765: String allowPingbacks = BlojsomUtils
0766: .getRequestValue(
0767: BlojsomMetaDataConstants.BLOG_METADATA_PINGBACKS_DISABLED,
0768: httpServletRequest);
0769: String blogTrackbackURLs = BlojsomUtils.getRequestValue(
0770: BLOG_TRACKBACK_URLS, httpServletRequest);
0771: String pingBlogURLS = BlojsomUtils.getRequestValue(
0772: PING_BLOG_URLS, httpServletRequest);
0773: String postSlug = BlojsomUtils.getRequestValue(POST_SLUG,
0774: httpServletRequest);
0775: String sendPingbacks = BlojsomUtils
0776: .getRequestValue(
0777: PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS,
0778: httpServletRequest);
0779: String status = BlojsomUtils.getRequestValue(STATUS,
0780: httpServletRequest);
0781:
0782: Entry entry;
0783: entry = _fetcher.newEntry();
0784:
0785: entry.setBlogId(blog.getId());
0786: entry.setTitle(blogEntryTitle);
0787: entry.setBlogCategoryId(categoryId);
0788: entry.setDescription(blogEntryDescription);
0789: entry.setDate(new Date());
0790: entry.setModifiedDate(entry.getDate());
0791: entry.setBlogCategoryId(categoryId);
0792:
0793: if (!BlojsomUtils.checkNullOrBlank(postSlug)) {
0794: entry.setPostSlug(postSlug);
0795: }
0796:
0797: Map entryMetaData = new HashMap();
0798: username = (String) httpServletRequest
0799: .getSession()
0800: .getAttribute(
0801: blog.getBlogAdminURL() + "_"
0802: + BLOJSOM_ADMIN_PLUGIN_USERNAME_KEY);
0803: entry.setAuthor(username);
0804:
0805: String entryPublishDateTime = httpServletRequest
0806: .getParameter(BLOG_ENTRY_PUBLISH_DATETIME);
0807: if (!BlojsomUtils.checkNullOrBlank(entryPublishDateTime)) {
0808: SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
0809: "MM/dd/yyyy HH:mm:ss");
0810: try {
0811: Date publishDateTime = simpleDateFormat
0812: .parse(entryPublishDateTime);
0813: entry.setDate(publishDateTime);
0814: entry.setModifiedDate(publishDateTime);
0815: } catch (ParseException e) {
0816: }
0817: }
0818:
0819: if (!BlojsomUtils.checkNullOrBlank(allowComments)) {
0820: entry.setAllowComments(new Integer(0));
0821: } else {
0822: entry.setAllowComments(new Integer(1));
0823: }
0824:
0825: if (!BlojsomUtils.checkNullOrBlank(allowTrackbacks)) {
0826: entry.setAllowTrackbacks(new Integer(0));
0827: } else {
0828: entry.setAllowTrackbacks(new Integer(1));
0829: }
0830:
0831: if (!BlojsomUtils.checkNullOrBlank(allowPingbacks)) {
0832: entry.setAllowPingbacks(new Integer(0));
0833: } else {
0834: entry.setAllowPingbacks(new Integer(1));
0835: }
0836:
0837: if (BlojsomUtils.checkNullOrBlank(pingBlogURLS)) {
0838: entryMetaData.put(
0839: WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA,
0840: "true");
0841: } else {
0842: entryMetaData
0843: .remove(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA);
0844: }
0845:
0846: if (!BlojsomUtils.checkNullOrBlank(sendPingbacks)) {
0847: entryMetaData
0848: .put(
0849: PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS,
0850: "true");
0851: } else {
0852: entryMetaData
0853: .remove(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS);
0854: }
0855:
0856: if (BlojsomUtils.checkNullOrBlank(status)) {
0857: status = BlojsomMetaDataConstants.DRAFT_STATUS;
0858: }
0859:
0860: entry.setStatus(status);
0861: entry.setMetaData(entryMetaData);
0862:
0863: try {
0864: _eventBroadcaster.processEvent(new ProcessEntryEvent(
0865: this , new Date(), entry, blog,
0866: httpServletRequest, httpServletResponse,
0867: context));
0868:
0869: _fetcher.saveEntry(blog, entry);
0870: _fetcher.loadEntry(blog, entry);
0871:
0872: StringBuffer entryLink = new StringBuffer();
0873: entryLink.append("<a href=\"")
0874: .append(blog.getBlogURL()).append(
0875: entry.getBlogCategory().getName())
0876: .append(entry.getPostSlug()).append("\">")
0877: .append(entry.getEscapedTitle()).append("</a>");
0878: addOperationResultMessage(context, formatAdminResource(
0879: ADDED_BLOG_ENTRY_KEY, ADDED_BLOG_ENTRY_KEY,
0880: blog.getBlogAdministrationLocale(),
0881: new Object[] { entryLink.toString() }));
0882:
0883: EntryAddedEvent addedEvent = new EntryAddedEvent(this ,
0884: new Date(), entry, blog);
0885: _eventBroadcaster.broadcastEvent(addedEvent);
0886: } catch (FetcherException e) {
0887: if (_logger.isErrorEnabled()) {
0888: _logger.error(e);
0889: }
0890:
0891: addOperationResultMessage(context, formatAdminResource(
0892: FAILED_ADD_BLOG_ENTRY_KEY,
0893: FAILED_ADD_BLOG_ENTRY_KEY, blog
0894: .getBlogAdministrationLocale(),
0895: new Object[] { blogCategoryId }));
0896: httpServletRequest.setAttribute(
0897: BlojsomConstants.PAGE_PARAM,
0898: ADMIN_ADMINISTRATION_PAGE);
0899:
0900: return entries;
0901: }
0902:
0903: // Send trackback pings
0904: if (!BlojsomUtils.checkNullOrBlank(blogTrackbackURLs)) {
0905: sendTrackbackPings(blog, entry, blogTrackbackURLs);
0906: }
0907:
0908: httpServletRequest
0909: .setAttribute(BlojsomConstants.PAGE_PARAM,
0910: EDIT_BLOG_ENTRY_ACTION);
0911: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry);
0912: } else if (EDIT_ENTRIES_LIST.equals(action)) {
0913: if (_logger.isDebugEnabled()) {
0914: _logger
0915: .debug("User requested edit entries list action");
0916: }
0917:
0918: String page = BlojsomUtils.getRequestValue(
0919: BlojsomConstants.PAGE_NUMBER_PARAM,
0920: httpServletRequest);
0921: int pgNum;
0922: try {
0923: pgNum = Integer.parseInt(page);
0924: } catch (NumberFormatException e) {
0925: pgNum = 1;
0926: }
0927:
0928: if (pgNum < 1) {
0929: pgNum = 1;
0930: }
0931:
0932: try {
0933: if (DELETE_BLOG_ENTRY_LIST.equals(subAction)) {
0934: deleteBlogEntry(httpServletRequest, blog, context);
0935: }
0936:
0937: String query = BlojsomUtils.getRequestValue(QUERY,
0938: httpServletRequest);
0939: if (!BlojsomUtils.checkNullOrBlank(query)) {
0940: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST,
0941: _fetcher.findEntries(blog, query));
0942: context
0943: .put(QUERY, BlojsomUtils
0944: .escapeString(query));
0945: } else {
0946: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST,
0947: _fetcher.loadEntries(blog, 10, pgNum));
0948: }
0949:
0950: Integer totalEntries = _fetcher.countEntries(blog);
0951: int totalPages = (totalEntries.intValue() / 10);
0952: int totalRemaining = (totalEntries.intValue() % 10);
0953: if (totalRemaining > 0) {
0954: totalPages += 1;
0955: }
0956:
0957: context.put(BLOJSOM_PLUGIN_TOTAL_ENTRIES_PAGES,
0958: new Integer(totalPages));
0959: } catch (FetcherException e) {
0960: if (_logger.isErrorEnabled()) {
0961: _logger.error(e);
0962: }
0963: }
0964:
0965: context.put(BlojsomConstants.PAGE_NUMBER_PARAM,
0966: new Integer(pgNum));
0967: httpServletRequest.setAttribute(
0968: BlojsomConstants.PAGE_PARAM,
0969: MANAGE_BLOG_ENTRIES_PAGE);
0970: } else if (AJAX_DELETE_RESPONSE.equals(action)) {
0971: if (_logger.isDebugEnabled()) {
0972: _logger
0973: .debug("User requested AJAX delete response action");
0974: }
0975:
0976: String responseId = BlojsomUtils.getRequestValue(
0977: RESPONSE_ID, httpServletRequest);
0978: Integer responseID;
0979: try {
0980: responseID = Integer.valueOf(responseId);
0981: } catch (NumberFormatException e) {
0982: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
0983: BlojsomConstants.FAILURE);
0984: httpServletRequest.setAttribute(
0985: BlojsomConstants.PAGE_PARAM,
0986: ADMIN_AJAX_RESPONSE);
0987:
0988: return entries;
0989: }
0990:
0991: String responseType = BlojsomUtils.getRequestValue(
0992: RESPONSE_TYPE, httpServletRequest);
0993: try {
0994: if (Response.COMMENT_TYPE.equals(responseType)) {
0995: Comment comment = _fetcher.newComment();
0996: comment.setBlogId(blog.getId());
0997: comment.setId(responseID);
0998: _fetcher.loadComment(blog, comment);
0999: _fetcher.deleteComment(blog, comment);
1000:
1001: _eventBroadcaster
1002: .broadcastEvent(new CommentDeletedEvent(
1003: this , new Date(), comment, blog));
1004:
1005: if (_logger.isDebugEnabled()) {
1006: _logger
1007: .debug("AJAX delete comment response complete: "
1008: + responseId);
1009: }
1010: } else if (Response.TRACKBACK_TYPE.equals(responseType)) {
1011: Trackback trackback = _fetcher.newTrackback();
1012: trackback.setBlogId(blog.getId());
1013: trackback.setId(responseID);
1014: _fetcher.loadTrackback(blog, trackback);
1015: _fetcher.deleteTrackback(blog, trackback);
1016:
1017: _eventBroadcaster
1018: .broadcastEvent(new TrackbackDeletedEvent(
1019: this , new Date(), trackback, blog));
1020:
1021: if (_logger.isDebugEnabled()) {
1022: _logger
1023: .debug("AJAX delete trackback response complete: "
1024: + responseId);
1025: }
1026: } else if (Response.PINGBACK_TYPE.equals(responseType)) {
1027: Pingback pingback = _fetcher.newPingback();
1028: pingback.setBlogId(blog.getId());
1029: pingback.setId(responseID);
1030: _fetcher.loadPingback(blog, pingback);
1031: _fetcher.deletePingback(blog, pingback);
1032:
1033: _eventBroadcaster
1034: .broadcastEvent(new PingbackDeletedEvent(
1035: this , new Date(), pingback, blog));
1036:
1037: if (_logger.isDebugEnabled()) {
1038: _logger
1039: .debug("AJAX delete pingback response complete: "
1040: + responseId);
1041: }
1042: } else {
1043: if (_logger.isErrorEnabled()) {
1044: _logger
1045: .error("Unknown response type for AJAX delete response: "
1046: + responseType);
1047: }
1048: }
1049:
1050: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1051: BlojsomConstants.SUCCESS);
1052:
1053: httpServletRequest.setAttribute(
1054: BlojsomConstants.PAGE_PARAM,
1055: ADMIN_AJAX_RESPONSE);
1056: } catch (FetcherException e) {
1057: if (_logger.isErrorEnabled()) {
1058: _logger.error(e);
1059: }
1060:
1061: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1062: BlojsomConstants.FAILURE);
1063: httpServletRequest.setAttribute(
1064: BlojsomConstants.PAGE_PARAM,
1065: ADMIN_AJAX_RESPONSE);
1066:
1067: entries = new Entry[0];
1068: }
1069: } else if (AJAX_APPROVE_RESPONSE.equals(action)) {
1070: if (_logger.isDebugEnabled()) {
1071: _logger
1072: .debug("User requested AJAX approve response action");
1073: }
1074:
1075: String responseId = BlojsomUtils.getRequestValue(
1076: RESPONSE_ID, httpServletRequest);
1077: Integer responseID;
1078: try {
1079: responseID = Integer.valueOf(responseId);
1080: } catch (NumberFormatException e) {
1081: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1082: BlojsomConstants.FAILURE);
1083: httpServletRequest.setAttribute(
1084: BlojsomConstants.PAGE_PARAM,
1085: ADMIN_AJAX_RESPONSE);
1086:
1087: return entries;
1088: }
1089:
1090: String responseType = BlojsomUtils.getRequestValue(
1091: RESPONSE_TYPE, httpServletRequest);
1092: try {
1093: if (Response.COMMENT_TYPE.equals(responseType)) {
1094: Comment comment = _fetcher.newComment();
1095: comment.setBlogId(blog.getId());
1096: comment.setId(responseID);
1097: _fetcher.loadComment(blog, comment);
1098: comment
1099: .setStatus(ResponseConstants.APPROVED_STATUS);
1100: _fetcher.saveComment(blog, comment);
1101:
1102: _eventBroadcaster
1103: .broadcastEvent(new CommentApprovedEvent(
1104: this , new Date(), comment, blog));
1105:
1106: if (_logger.isDebugEnabled()) {
1107: _logger
1108: .debug("AJAX approve comment response complete: "
1109: + responseId);
1110: }
1111: } else if (Response.TRACKBACK_TYPE.equals(responseType)) {
1112: Trackback trackback = _fetcher.newTrackback();
1113: trackback.setBlogId(blog.getId());
1114: trackback.setId(responseID);
1115: _fetcher.loadTrackback(blog, trackback);
1116: trackback
1117: .setStatus(ResponseConstants.APPROVED_STATUS);
1118: _fetcher.saveTrackback(blog, trackback);
1119:
1120: _eventBroadcaster
1121: .broadcastEvent(new TrackbackApprovedEvent(
1122: this , new Date(), trackback, blog));
1123:
1124: if (_logger.isDebugEnabled()) {
1125: _logger
1126: .debug("AJAX approve trackback response complete: "
1127: + responseId);
1128: }
1129: } else if (Response.PINGBACK_TYPE.equals(responseType)) {
1130: Pingback pingback = _fetcher.newPingback();
1131: pingback.setBlogId(blog.getId());
1132: pingback.setId(responseID);
1133: _fetcher.loadPingback(blog, pingback);
1134: pingback
1135: .setStatus(ResponseConstants.APPROVED_STATUS);
1136: _fetcher.savePingback(blog, pingback);
1137:
1138: _eventBroadcaster
1139: .broadcastEvent(new PingbackApprovedEvent(
1140: this , new Date(), pingback, blog));
1141:
1142: if (_logger.isDebugEnabled()) {
1143: _logger
1144: .debug("AJAX approve pingback response complete: "
1145: + responseId);
1146: }
1147: } else {
1148: if (_logger.isErrorEnabled()) {
1149: _logger
1150: .error("Unknown response type for AJAX approve response: "
1151: + responseType);
1152: }
1153: }
1154:
1155: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1156: BlojsomConstants.SUCCESS);
1157:
1158: httpServletRequest.setAttribute(
1159: BlojsomConstants.PAGE_PARAM,
1160: ADMIN_AJAX_RESPONSE);
1161: } catch (FetcherException e) {
1162: if (_logger.isErrorEnabled()) {
1163: _logger.error(e);
1164: }
1165:
1166: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1167: BlojsomConstants.FAILURE);
1168: httpServletRequest.setAttribute(
1169: BlojsomConstants.PAGE_PARAM,
1170: ADMIN_AJAX_RESPONSE);
1171:
1172: entries = new Entry[0];
1173: }
1174: } else if (AJAX_UNAPPROVE_RESPONSE.equals(action)) {
1175: if (_logger.isDebugEnabled()) {
1176: _logger
1177: .debug("User requested AJAX unapprove response action");
1178: }
1179:
1180: String responseId = BlojsomUtils.getRequestValue(
1181: RESPONSE_ID, httpServletRequest);
1182: Integer responseID;
1183: try {
1184: responseID = Integer.valueOf(responseId);
1185: } catch (NumberFormatException e) {
1186: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1187: BlojsomConstants.FAILURE);
1188: httpServletRequest.setAttribute(
1189: BlojsomConstants.PAGE_PARAM,
1190: ADMIN_AJAX_RESPONSE);
1191:
1192: return entries;
1193: }
1194:
1195: String responseType = BlojsomUtils.getRequestValue(
1196: RESPONSE_TYPE, httpServletRequest);
1197: try {
1198: if (Response.COMMENT_TYPE.equals(responseType)) {
1199: Comment comment = _fetcher.newComment();
1200: comment.setBlogId(blog.getId());
1201: comment.setId(responseID);
1202: _fetcher.loadComment(blog, comment);
1203: comment.setStatus(ResponseConstants.NEW_STATUS);
1204: _fetcher.saveComment(blog, comment);
1205:
1206: _eventBroadcaster
1207: .broadcastEvent(new CommentUnapprovedEvent(
1208: this , new Date(), comment, blog));
1209:
1210: if (_logger.isDebugEnabled()) {
1211: _logger
1212: .debug("AJAX unapprove comment response complete: "
1213: + responseId);
1214: }
1215: } else if (Response.TRACKBACK_TYPE.equals(responseType)) {
1216: Trackback trackback = _fetcher.newTrackback();
1217: trackback.setBlogId(blog.getId());
1218: trackback.setId(responseID);
1219: _fetcher.loadTrackback(blog, trackback);
1220: trackback.setStatus(ResponseConstants.NEW_STATUS);
1221: _fetcher.saveTrackback(blog, trackback);
1222:
1223: _eventBroadcaster
1224: .broadcastEvent(new TrackbackUnapprovedEvent(
1225: this , new Date(), trackback, blog));
1226:
1227: if (_logger.isDebugEnabled()) {
1228: _logger
1229: .debug("AJAX unapprove trackback response complete: "
1230: + responseId);
1231: }
1232: } else if (Response.PINGBACK_TYPE.equals(responseType)) {
1233: Pingback pingback = _fetcher.newPingback();
1234: pingback.setBlogId(blog.getId());
1235: pingback.setId(responseID);
1236: _fetcher.loadPingback(blog, pingback);
1237: pingback.setStatus(ResponseConstants.NEW_STATUS);
1238: _fetcher.savePingback(blog, pingback);
1239:
1240: _eventBroadcaster
1241: .broadcastEvent(new PingbackUnapprovedEvent(
1242: this , new Date(), pingback, blog));
1243:
1244: if (_logger.isDebugEnabled()) {
1245: _logger
1246: .debug("AJAX unapprove pingback response complete: "
1247: + responseId);
1248: }
1249: } else {
1250: if (_logger.isErrorEnabled()) {
1251: _logger
1252: .error("Unknown response type for AJAX unapprove response: "
1253: + responseType);
1254: }
1255: }
1256:
1257: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1258: BlojsomConstants.SUCCESS);
1259:
1260: httpServletRequest.setAttribute(
1261: BlojsomConstants.PAGE_PARAM,
1262: ADMIN_AJAX_RESPONSE);
1263: } catch (FetcherException e) {
1264: if (_logger.isErrorEnabled()) {
1265: _logger.error(e);
1266: }
1267:
1268: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1269: BlojsomConstants.FAILURE);
1270: httpServletRequest.setAttribute(
1271: BlojsomConstants.PAGE_PARAM,
1272: ADMIN_AJAX_RESPONSE);
1273:
1274: entries = new Entry[0];
1275: }
1276: } else if (AJAX_MARK_SPAM_RESPONSE.equals(action)) {
1277: if (_logger.isDebugEnabled()) {
1278: _logger
1279: .debug("User requested AJAX mark spam response action");
1280: }
1281:
1282: String responseId = BlojsomUtils.getRequestValue(
1283: RESPONSE_ID, httpServletRequest);
1284: Integer responseID;
1285: try {
1286: responseID = Integer.valueOf(responseId);
1287: } catch (NumberFormatException e) {
1288: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1289: BlojsomConstants.FAILURE);
1290: httpServletRequest.setAttribute(
1291: BlojsomConstants.PAGE_PARAM,
1292: ADMIN_AJAX_RESPONSE);
1293:
1294: return entries;
1295: }
1296:
1297: String responseType = BlojsomUtils.getRequestValue(
1298: RESPONSE_TYPE, httpServletRequest);
1299: try {
1300: if (Response.COMMENT_TYPE.equals(responseType)) {
1301: Comment comment = _fetcher.newComment();
1302: comment.setBlogId(blog.getId());
1303: comment.setId(responseID);
1304: _fetcher.loadComment(blog, comment);
1305: comment.setStatus(ResponseConstants.SPAM_STATUS);
1306: _fetcher.saveComment(blog, comment);
1307:
1308: _eventBroadcaster
1309: .broadcastEvent(new CommentMarkedSpamEvent(
1310: this , new Date(), comment, blog));
1311:
1312: if (_logger.isDebugEnabled()) {
1313: _logger
1314: .debug("AJAX mark comment spam response complete: "
1315: + responseId);
1316: }
1317: } else if (Response.TRACKBACK_TYPE.equals(responseType)) {
1318: Trackback trackback = _fetcher.newTrackback();
1319: trackback.setBlogId(blog.getId());
1320: trackback.setId(responseID);
1321: _fetcher.loadTrackback(blog, trackback);
1322: trackback.setStatus(ResponseConstants.SPAM_STATUS);
1323: _fetcher.saveTrackback(blog, trackback);
1324:
1325: _eventBroadcaster
1326: .broadcastEvent(new TrackbackMarkedSpamEvent(
1327: this , new Date(), trackback, blog));
1328:
1329: if (_logger.isDebugEnabled()) {
1330: _logger
1331: .debug("AJAX mark trackback spam response complete: "
1332: + responseId);
1333: }
1334: } else if (Response.PINGBACK_TYPE.equals(responseType)) {
1335: Pingback pingback = _fetcher.newPingback();
1336: pingback.setBlogId(blog.getId());
1337: pingback.setId(responseID);
1338: _fetcher.loadPingback(blog, pingback);
1339: pingback.setStatus(ResponseConstants.SPAM_STATUS);
1340: _fetcher.savePingback(blog, pingback);
1341:
1342: _eventBroadcaster
1343: .broadcastEvent(new PingbackMarkedSpamEvent(
1344: this , new Date(), pingback, blog));
1345:
1346: if (_logger.isDebugEnabled()) {
1347: _logger
1348: .debug("AJAX mark pingback spam response complete: "
1349: + responseId);
1350: }
1351: } else {
1352: if (_logger.isErrorEnabled()) {
1353: _logger
1354: .error("Unknown response type for AJAX mark spam response: "
1355: + responseType);
1356: }
1357: }
1358:
1359: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1360: BlojsomConstants.SUCCESS);
1361:
1362: httpServletRequest.setAttribute(
1363: BlojsomConstants.PAGE_PARAM,
1364: ADMIN_AJAX_RESPONSE);
1365: } catch (FetcherException e) {
1366: if (_logger.isErrorEnabled()) {
1367: _logger.error(e);
1368: }
1369:
1370: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1371: BlojsomConstants.FAILURE);
1372: httpServletRequest.setAttribute(
1373: BlojsomConstants.PAGE_PARAM,
1374: ADMIN_AJAX_RESPONSE);
1375:
1376: entries = new Entry[0];
1377: }
1378: } else if (AJAX_UNMARK_SPAM_RESPONSE.equals(action)) {
1379: if (_logger.isDebugEnabled()) {
1380: _logger
1381: .debug("User requested AJAX unmark spam response action");
1382: }
1383:
1384: String responseId = BlojsomUtils.getRequestValue(
1385: RESPONSE_ID, httpServletRequest);
1386: Integer responseID;
1387: try {
1388: responseID = Integer.valueOf(responseId);
1389: } catch (NumberFormatException e) {
1390: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1391: BlojsomConstants.FAILURE);
1392: httpServletRequest.setAttribute(
1393: BlojsomConstants.PAGE_PARAM,
1394: ADMIN_AJAX_RESPONSE);
1395:
1396: return entries;
1397: }
1398:
1399: String responseType = BlojsomUtils.getRequestValue(
1400: RESPONSE_TYPE, httpServletRequest);
1401: try {
1402: if (Response.COMMENT_TYPE.equals(responseType)) {
1403: Comment comment = _fetcher.newComment();
1404: comment.setBlogId(blog.getId());
1405: comment.setId(responseID);
1406: _fetcher.loadComment(blog, comment);
1407: comment.setStatus(ResponseConstants.NEW_STATUS);
1408: _fetcher.saveComment(blog, comment);
1409:
1410: _eventBroadcaster
1411: .broadcastEvent(new CommentUnmarkedSpamEvent(
1412: this , new Date(), comment, blog));
1413:
1414: if (_logger.isDebugEnabled()) {
1415: _logger
1416: .debug("AJAX unmark comment spam response complete: "
1417: + responseId);
1418: }
1419: } else if (Response.TRACKBACK_TYPE.equals(responseType)) {
1420: Trackback trackback = _fetcher.newTrackback();
1421: trackback.setBlogId(blog.getId());
1422: trackback.setId(responseID);
1423: _fetcher.loadTrackback(blog, trackback);
1424: trackback.setStatus(ResponseConstants.NEW_STATUS);
1425: _fetcher.saveTrackback(blog, trackback);
1426:
1427: _eventBroadcaster
1428: .broadcastEvent(new TrackbackUnmarkedSpamEvent(
1429: this , new Date(), trackback, blog));
1430:
1431: if (_logger.isDebugEnabled()) {
1432: _logger
1433: .debug("AJAX unmark trackback spam response complete: "
1434: + responseId);
1435: }
1436: } else if (Response.PINGBACK_TYPE.equals(responseType)) {
1437: Pingback pingback = _fetcher.newPingback();
1438: pingback.setBlogId(blog.getId());
1439: pingback.setId(responseID);
1440: _fetcher.loadPingback(blog, pingback);
1441: pingback.setStatus(ResponseConstants.NEW_STATUS);
1442: _fetcher.savePingback(blog, pingback);
1443:
1444: _eventBroadcaster
1445: .broadcastEvent(new PingbackUnmarkedSpamEvent(
1446: this , new Date(), pingback, blog));
1447:
1448: if (_logger.isDebugEnabled()) {
1449: _logger
1450: .debug("AJAX unmark pingback spam response complete: "
1451: + responseId);
1452: }
1453: } else {
1454: if (_logger.isErrorEnabled()) {
1455: _logger
1456: .error("Unknown response type for AJAX mark spam response: "
1457: + responseType);
1458: }
1459: }
1460:
1461: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1462: BlojsomConstants.SUCCESS);
1463:
1464: httpServletRequest.setAttribute(
1465: BlojsomConstants.PAGE_PARAM,
1466: ADMIN_AJAX_RESPONSE);
1467: } catch (FetcherException e) {
1468: if (_logger.isErrorEnabled()) {
1469: _logger.error(e);
1470: }
1471:
1472: context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS,
1473: BlojsomConstants.FAILURE);
1474: httpServletRequest.setAttribute(
1475: BlojsomConstants.PAGE_PARAM,
1476: ADMIN_AJAX_RESPONSE);
1477:
1478: entries = new Entry[0];
1479: }
1480: } else if (DELETE_BLOG_COMMENTS.equals(action)) {
1481: if (_logger.isDebugEnabled()) {
1482: _logger.debug("User requested delete comments action");
1483: }
1484:
1485: String blogEntryId = BlojsomUtils.getRequestValue(
1486: BLOG_ENTRY_ID, httpServletRequest);
1487: Integer entryId;
1488: try {
1489: entryId = Integer.valueOf(blogEntryId);
1490: } catch (NumberFormatException e) {
1491: addOperationResultMessage(context, formatAdminResource(
1492: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1493: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1494: .getBlogAdministrationLocale(),
1495: new Object[] { blogEntryId }));
1496: httpServletRequest.setAttribute(
1497: BlojsomConstants.PAGE_PARAM,
1498: EDIT_BLOG_ENTRY_PAGE);
1499:
1500: return entries;
1501: }
1502:
1503: Entry entry;
1504: try {
1505: entry = _fetcher.loadEntry(blog, entryId);
1506: String[] blogCommentIDs = httpServletRequest
1507: .getParameterValues(BLOG_COMMENT_ID);
1508:
1509: if (blogCommentIDs != null && blogCommentIDs.length > 0) {
1510: for (int i = 0; i < blogCommentIDs.length; i++) {
1511: String blogCommentID = blogCommentIDs[i];
1512: Comment[] blogComments = entry
1513: .getCommentsAsArray();
1514: for (int j = 0; j < blogComments.length; j++) {
1515: Comment blogComment = blogComments[j];
1516: if (blogComment.getId().equals(
1517: Integer.valueOf(blogCommentID))) {
1518: try {
1519: _fetcher.deleteComment(blog,
1520: blogComment);
1521:
1522: _eventBroadcaster
1523: .broadcastEvent(new CommentDeletedEvent(
1524: this , new Date(),
1525: blogComment, blog));
1526: } catch (FetcherException e) {
1527: if (_logger.isErrorEnabled()) {
1528: _logger.error(e);
1529: }
1530: }
1531: }
1532: }
1533: }
1534:
1535: addOperationResultMessage(context,
1536: formatAdminResource(DELETED_COMMENTS_KEY,
1537: DELETED_COMMENTS_KEY,
1538: blog.getBlogAdministrationLocale(),
1539: new Object[] { new Integer(
1540: blogCommentIDs.length) }));
1541: }
1542:
1543: _fetcher.loadEntry(blog, entry);
1544:
1545: _eventBroadcaster.processEvent(new ProcessEntryEvent(
1546: this , new Date(), entry, blog,
1547: httpServletRequest, httpServletResponse,
1548: context));
1549:
1550: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
1551: entry);
1552: } catch (FetcherException e) {
1553: if (_logger.isErrorEnabled()) {
1554: _logger.error(e);
1555: }
1556:
1557: addOperationResultMessage(context, formatAdminResource(
1558: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1559: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1560: .getBlogAdministrationLocale(),
1561: new Object[] { blogEntryId }));
1562: entries = new Entry[0];
1563: }
1564:
1565: httpServletRequest.setAttribute(
1566: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
1567: } else if (APPROVE_BLOG_COMMENTS.equals(action)) {
1568: if (_logger.isDebugEnabled()) {
1569: _logger.debug("User requested approve comments action");
1570: }
1571:
1572: String blogEntryId = BlojsomUtils.getRequestValue(
1573: BLOG_ENTRY_ID, httpServletRequest);
1574: Integer entryId;
1575: try {
1576: entryId = Integer.valueOf(blogEntryId);
1577: } catch (NumberFormatException e) {
1578: addOperationResultMessage(context, formatAdminResource(
1579: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1580: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1581: .getBlogAdministrationLocale(),
1582: new Object[] { blogEntryId }));
1583: httpServletRequest.setAttribute(
1584: BlojsomConstants.PAGE_PARAM,
1585: EDIT_BLOG_ENTRY_PAGE);
1586:
1587: return entries;
1588: }
1589:
1590: Entry entry;
1591: try {
1592: entry = _fetcher.loadEntry(blog, entryId);
1593: String[] blogCommentIDs = httpServletRequest
1594: .getParameterValues(BLOG_COMMENT_ID);
1595:
1596: if (blogCommentIDs != null && blogCommentIDs.length > 0) {
1597: for (int i = 0; i < blogCommentIDs.length; i++) {
1598: String blogCommentID = blogCommentIDs[i];
1599: Comment[] blogComments = entry
1600: .getCommentsAsArray();
1601: for (int j = 0; j < blogComments.length; j++) {
1602: Comment blogComment = blogComments[j];
1603: if (blogComment.getId().equals(
1604: Integer.valueOf(blogCommentID))) {
1605: try {
1606: blogComment
1607: .setStatus(ResponseConstants.APPROVED_STATUS);
1608: _fetcher.saveComment(blog,
1609: blogComment);
1610:
1611: _eventBroadcaster
1612: .broadcastEvent(new CommentApprovedEvent(
1613: this , new Date(),
1614: blogComment, blog));
1615: } catch (FetcherException e) {
1616: _logger.error(e);
1617: }
1618: }
1619: }
1620: }
1621:
1622: addOperationResultMessage(context,
1623: formatAdminResource(APPROVED_COMMENTS_KEY,
1624: APPROVED_COMMENTS_KEY,
1625: blog.getBlogAdministrationLocale(),
1626: new Object[] { new Integer(
1627: blogCommentIDs.length) }));
1628: }
1629:
1630: _fetcher.loadEntry(blog, entry);
1631:
1632: _eventBroadcaster.processEvent(new ProcessEntryEvent(
1633: this , new Date(), entry, blog,
1634: httpServletRequest, httpServletResponse,
1635: context));
1636:
1637: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
1638: entry);
1639: } catch (FetcherException e) {
1640: if (_logger.isErrorEnabled()) {
1641: _logger.error(e);
1642: }
1643:
1644: addOperationResultMessage(context, formatAdminResource(
1645: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1646: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1647: .getBlogAdministrationLocale(),
1648: new Object[] { blogEntryId }));
1649: entries = new Entry[0];
1650: }
1651:
1652: httpServletRequest.setAttribute(
1653: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
1654: } else if (DELETE_BLOG_TRACKBACKS.equals(action)) {
1655: if (_logger.isDebugEnabled()) {
1656: _logger
1657: .debug("User requested delete blog trackbacks action");
1658: }
1659:
1660: String blogEntryId = BlojsomUtils.getRequestValue(
1661: BLOG_ENTRY_ID, httpServletRequest);
1662: Integer entryId;
1663: try {
1664: entryId = Integer.valueOf(blogEntryId);
1665: } catch (NumberFormatException e) {
1666: addOperationResultMessage(context, formatAdminResource(
1667: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1668: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1669: .getBlogAdministrationLocale(),
1670: new Object[] { blogEntryId }));
1671: httpServletRequest.setAttribute(
1672: BlojsomConstants.PAGE_PARAM,
1673: EDIT_BLOG_ENTRY_PAGE);
1674:
1675: return entries;
1676: }
1677:
1678: Entry entry;
1679: try {
1680: entry = _fetcher.loadEntry(blog, entryId);
1681: String[] blogTrackbackIDs = httpServletRequest
1682: .getParameterValues(BLOG_TRACKBACK_ID);
1683:
1684: if (blogTrackbackIDs != null
1685: && blogTrackbackIDs.length > 0) {
1686: for (int i = 0; i < blogTrackbackIDs.length; i++) {
1687: String blogTrackbackID = blogTrackbackIDs[i];
1688: Trackback[] trackbacks = entry
1689: .getTrackbacksAsArray();
1690: for (int j = 0; j < trackbacks.length; j++) {
1691: Trackback trackback = trackbacks[j];
1692: if (trackback.getId().equals(
1693: Integer.valueOf(blogTrackbackID))) {
1694: try {
1695: _fetcher.deleteTrackback(blog,
1696: trackback);
1697:
1698: _eventBroadcaster
1699: .broadcastEvent(new TrackbackDeletedEvent(
1700: this , new Date(),
1701: trackback, blog));
1702: } catch (FetcherException e) {
1703: if (_logger.isErrorEnabled()) {
1704: _logger.error(e);
1705: }
1706: }
1707: }
1708: }
1709: }
1710:
1711: addOperationResultMessage(context,
1712: formatAdminResource(DELETED_TRACKBACKS_KEY,
1713: DELETED_TRACKBACKS_KEY,
1714: blog.getBlogAdministrationLocale(),
1715: new Object[] { new Integer(
1716: blogTrackbackIDs.length) }));
1717: }
1718:
1719: _fetcher.loadEntry(blog, entry);
1720:
1721: _eventBroadcaster.processEvent(new ProcessEntryEvent(
1722: this , new Date(), entry, blog,
1723: httpServletRequest, httpServletResponse,
1724: context));
1725:
1726: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
1727: entry);
1728: } catch (FetcherException e) {
1729: if (_logger.isErrorEnabled()) {
1730: _logger.error(e);
1731: }
1732:
1733: addOperationResultMessage(context, formatAdminResource(
1734: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1735: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1736: .getBlogAdministrationLocale(),
1737: new Object[] { blogEntryId }));
1738: entries = new Entry[0];
1739: }
1740:
1741: httpServletRequest.setAttribute(
1742: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
1743: } else if (APPROVE_BLOG_TRACKBACKS.equals(action)) {
1744: if (_logger.isDebugEnabled()) {
1745: _logger
1746: .debug("User requested approve blog trackbacks action");
1747: }
1748:
1749: String blogEntryId = BlojsomUtils.getRequestValue(
1750: BLOG_ENTRY_ID, httpServletRequest);
1751: Integer entryId;
1752: try {
1753: entryId = Integer.valueOf(blogEntryId);
1754: } catch (NumberFormatException e) {
1755: addOperationResultMessage(context, formatAdminResource(
1756: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1757: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1758: .getBlogAdministrationLocale(),
1759: new Object[] { blogEntryId }));
1760: httpServletRequest.setAttribute(
1761: BlojsomConstants.PAGE_PARAM,
1762: EDIT_BLOG_ENTRY_PAGE);
1763:
1764: return entries;
1765: }
1766:
1767: Entry entry;
1768: try {
1769: entry = _fetcher.loadEntry(blog, entryId);
1770: String[] blogTrackbackIDs = httpServletRequest
1771: .getParameterValues(BLOG_TRACKBACK_ID);
1772:
1773: if (blogTrackbackIDs != null
1774: && blogTrackbackIDs.length > 0) {
1775: for (int i = 0; i < blogTrackbackIDs.length; i++) {
1776: String blogTrackbackID = blogTrackbackIDs[i];
1777: Trackback[] trackbacks = entry
1778: .getTrackbacksAsArray();
1779: for (int j = 0; j < trackbacks.length; j++) {
1780: Trackback trackback = trackbacks[j];
1781: if (trackback.getId().equals(
1782: Integer.valueOf(blogTrackbackID))) {
1783: try {
1784: trackback
1785: .setStatus(ResponseConstants.APPROVED_STATUS);
1786: _fetcher.saveTrackback(blog,
1787: trackback);
1788:
1789: _eventBroadcaster
1790: .broadcastEvent(new TrackbackApprovedEvent(
1791: this , new Date(),
1792: trackback, blog));
1793: } catch (FetcherException e) {
1794: if (_logger.isErrorEnabled()) {
1795: _logger.error(e);
1796: }
1797: }
1798: }
1799: }
1800: }
1801:
1802: addOperationResultMessage(context,
1803: formatAdminResource(
1804: APPROVED_TRACKBACKS_KEY,
1805: APPROVED_TRACKBACKS_KEY,
1806: blog.getBlogAdministrationLocale(),
1807: new Object[] { new Integer(
1808: blogTrackbackIDs.length) }));
1809: }
1810:
1811: _fetcher.loadEntry(blog, entry);
1812:
1813: _eventBroadcaster.processEvent(new ProcessEntryEvent(
1814: this , new Date(), entry, blog,
1815: httpServletRequest, httpServletResponse,
1816: context));
1817:
1818: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
1819: entry);
1820: } catch (FetcherException e) {
1821: if (_logger.isErrorEnabled()) {
1822: _logger.error(e);
1823: }
1824:
1825: addOperationResultMessage(context, formatAdminResource(
1826: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1827: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1828: .getBlogAdministrationLocale(),
1829: new Object[] { blogEntryId }));
1830: entries = new Entry[0];
1831: }
1832:
1833: httpServletRequest.setAttribute(
1834: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
1835: } else if (DELETE_BLOG_PINGBACKS.equals(action)) {
1836: if (_logger.isDebugEnabled()) {
1837: _logger
1838: .debug("User requested delete blog pingbacks action");
1839: }
1840:
1841: String blogEntryId = BlojsomUtils.getRequestValue(
1842: BLOG_ENTRY_ID, httpServletRequest);
1843: Integer entryId;
1844: try {
1845: entryId = Integer.valueOf(blogEntryId);
1846: } catch (NumberFormatException e) {
1847: addOperationResultMessage(context, formatAdminResource(
1848: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1849: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1850: .getBlogAdministrationLocale(),
1851: new Object[] { blogEntryId }));
1852: httpServletRequest.setAttribute(
1853: BlojsomConstants.PAGE_PARAM,
1854: EDIT_BLOG_ENTRY_PAGE);
1855:
1856: return entries;
1857: }
1858:
1859: Entry entry;
1860: try {
1861: entry = _fetcher.loadEntry(blog, entryId);
1862: String[] blogPingbackIDs = httpServletRequest
1863: .getParameterValues(BLOG_PINGBACK_ID);
1864:
1865: if (blogPingbackIDs != null
1866: && blogPingbackIDs.length > 0) {
1867: for (int i = 0; i < blogPingbackIDs.length; i++) {
1868: String blogPingbackID = blogPingbackIDs[i];
1869: Pingback[] pingbacks = entry
1870: .getPingbacksAsArray();
1871: for (int j = 0; j < pingbacks.length; j++) {
1872: Pingback pingback = pingbacks[j];
1873: if (pingback.getId().equals(
1874: Integer.valueOf(blogPingbackID))) {
1875: try {
1876: _fetcher.deletePingback(blog,
1877: pingback);
1878:
1879: _eventBroadcaster
1880: .broadcastEvent(new PingbackDeletedEvent(
1881: this , new Date(),
1882: pingback, blog));
1883: } catch (FetcherException e) {
1884: if (_logger.isErrorEnabled()) {
1885: _logger.error(e);
1886: }
1887: }
1888: }
1889: }
1890: }
1891:
1892: addOperationResultMessage(context,
1893: formatAdminResource(DELETED_PINGBACKS_KEY,
1894: DELETED_PINGBACKS_KEY,
1895: blog.getBlogAdministrationLocale(),
1896: new Object[] { new Integer(
1897: blogPingbackIDs.length) }));
1898: }
1899:
1900: _fetcher.loadEntry(blog, entry);
1901:
1902: _eventBroadcaster.processEvent(new ProcessEntryEvent(
1903: this , new Date(), entry, blog,
1904: httpServletRequest, httpServletResponse,
1905: context));
1906:
1907: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
1908: entry);
1909: } catch (FetcherException e) {
1910: if (_logger.isErrorEnabled()) {
1911: _logger.error(e);
1912: }
1913:
1914: addOperationResultMessage(context, formatAdminResource(
1915: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1916: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1917: .getBlogAdministrationLocale(),
1918: new Object[] { blogEntryId }));
1919: entries = new Entry[0];
1920: }
1921:
1922: httpServletRequest.setAttribute(
1923: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
1924: } else if (APPROVE_BLOG_PINGBACKS.equals(action)) {
1925: if (_logger.isDebugEnabled()) {
1926: _logger
1927: .debug("User requested approve blog pingbacks action");
1928: }
1929:
1930: String blogEntryId = BlojsomUtils.getRequestValue(
1931: BLOG_ENTRY_ID, httpServletRequest);
1932: Integer entryId;
1933: try {
1934: entryId = Integer.valueOf(blogEntryId);
1935: } catch (NumberFormatException e) {
1936:
1937: addOperationResultMessage(context, formatAdminResource(
1938: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
1939: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
1940: .getBlogAdministrationLocale(),
1941: new Object[] { blogEntryId }));
1942: httpServletRequest.setAttribute(
1943: BlojsomConstants.PAGE_PARAM,
1944: EDIT_BLOG_ENTRY_PAGE);
1945:
1946: return entries;
1947: }
1948:
1949: Entry entry;
1950: try {
1951: entry = _fetcher.loadEntry(blog, entryId);
1952: String[] blogPingbackIDs = httpServletRequest
1953: .getParameterValues(BLOG_PINGBACK_ID);
1954:
1955: if (blogPingbackIDs != null
1956: && blogPingbackIDs.length > 0) {
1957: for (int i = 0; i < blogPingbackIDs.length; i++) {
1958: String blogPingbackID = blogPingbackIDs[i];
1959: Pingback[] pingbacks = entry
1960: .getPingbacksAsArray();
1961: for (int j = 0; j < pingbacks.length; j++) {
1962: Pingback pingback = pingbacks[j];
1963: if (pingback.getId().equals(
1964: Integer.valueOf(blogPingbackID))) {
1965: try {
1966: pingback
1967: .setStatus(ResponseConstants.APPROVED_STATUS);
1968: _fetcher.savePingback(blog,
1969: pingback);
1970:
1971: _eventBroadcaster
1972: .broadcastEvent(new PingbackApprovedEvent(
1973: this , new Date(),
1974: pingback, blog));
1975: } catch (FetcherException e) {
1976: if (_logger.isErrorEnabled()) {
1977: _logger.error(e);
1978: }
1979: }
1980: }
1981: }
1982: }
1983:
1984: addOperationResultMessage(context,
1985: formatAdminResource(APPROVED_PINGBACKS_KEY,
1986: APPROVED_PINGBACKS_KEY,
1987: blog.getBlogAdministrationLocale(),
1988: new Object[] { new Integer(
1989: blogPingbackIDs.length) }));
1990: }
1991:
1992: _fetcher.loadEntry(blog, entry);
1993:
1994: _eventBroadcaster.processEvent(new ProcessEntryEvent(
1995: this , new Date(), entry, blog,
1996: httpServletRequest, httpServletResponse,
1997: context));
1998:
1999: context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY,
2000: entry);
2001: } catch (FetcherException e) {
2002: if (_logger.isErrorEnabled()) {
2003: _logger.error(e);
2004: }
2005:
2006: addOperationResultMessage(context, formatAdminResource(
2007: FAILED_RETRIEVE_BLOG_ENTRY_KEY,
2008: FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog
2009: .getBlogAdministrationLocale(),
2010: new Object[] { blogEntryId }));
2011: entries = new Entry[0];
2012: }
2013:
2014: httpServletRequest.setAttribute(
2015: BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE);
2016: }
2017:
2018: return entries;
2019: }
2020:
2021: /**
2022: * Send trackback pings to a comma-separated list of trackback URLs
2023: *
2024: * @param blog Blog information
2025: * @param entry Blog entry
2026: * @param blogTrackbackURLs Trackback URLs
2027: */
2028: protected void sendTrackbackPings(Blog blog, Entry entry,
2029: String blogTrackbackURLs) {
2030: // Build the URL parameters for the trackback ping URL
2031: StringBuffer trackbackPingURLParameters = new StringBuffer();
2032: try {
2033: StringBuffer entryLink = new StringBuffer(blog.getBlogURL())
2034: .append(entry.getBlogCategory().getName()).append(
2035: entry.getPostSlug());
2036: trackbackPingURLParameters.append("&").append(
2037: TrackbackPlugin.TRACKBACK_URL_PARAM).append("=")
2038: .append(entryLink);
2039: trackbackPingURLParameters.append("&").append(
2040: TrackbackPlugin.TRACKBACK_TITLE_PARAM).append("=")
2041: .append(
2042: URLEncoder.encode(entry.getTitle(),
2043: BlojsomConstants.UTF8));
2044: trackbackPingURLParameters.append("&").append(
2045: TrackbackPlugin.TRACKBACK_BLOG_NAME_PARAM).append(
2046: "=").append(
2047: URLEncoder.encode(blog.getBlogName(),
2048: BlojsomConstants.UTF8));
2049:
2050: String excerpt = entry.getDescription().replaceAll("<.*?>",
2051: "");
2052: if (excerpt.length() > 255) {
2053: excerpt = excerpt.substring(0, 251);
2054: excerpt += "...";
2055: }
2056: trackbackPingURLParameters.append("&").append(
2057: TrackbackPlugin.TRACKBACK_EXCERPT_PARAM)
2058: .append("=").append(
2059: URLEncoder.encode(excerpt,
2060: BlojsomConstants.UTF8));
2061: } catch (UnsupportedEncodingException e) {
2062: if (_logger.isErrorEnabled()) {
2063: _logger.error(e);
2064: }
2065: }
2066:
2067: String[] trackbackURLs = BlojsomUtils.parseDelimitedList(
2068: blogTrackbackURLs, BlojsomConstants.WHITESPACE);
2069: if (trackbackURLs != null && trackbackURLs.length > 0) {
2070: for (int i = 0; i < trackbackURLs.length; i++) {
2071: String trackbackURL = trackbackURLs[i].trim();
2072: StringBuffer trackbackPingURL = new StringBuffer(
2073: trackbackURL);
2074:
2075: if (_logger.isDebugEnabled()) {
2076: _logger
2077: .debug("Automatically sending trackback ping to URL: "
2078: + trackbackPingURL.toString());
2079: }
2080:
2081: try {
2082: URL trackbackUrl = new URL(trackbackPingURL
2083: .toString());
2084:
2085: // Open a connection to the trackback URL and read its input
2086: HttpURLConnection trackbackUrlConnection = (HttpURLConnection) trackbackUrl
2087: .openConnection();
2088: trackbackUrlConnection.setRequestMethod("POST");
2089: trackbackUrlConnection.setRequestProperty(
2090: "Content-Encoding", BlojsomConstants.UTF8);
2091: trackbackUrlConnection.setRequestProperty(
2092: "Content-Type",
2093: "application/x-www-form-urlencoded");
2094: trackbackUrlConnection.setRequestProperty(
2095: "Content-Length", ""
2096: + trackbackPingURLParameters
2097: .length());
2098: trackbackUrlConnection.setDoOutput(true);
2099: trackbackUrlConnection.getOutputStream().write(
2100: trackbackPingURLParameters.toString()
2101: .getBytes(BlojsomConstants.UTF8));
2102: trackbackUrlConnection.connect();
2103: BufferedReader trackbackStatus = new BufferedReader(
2104: new InputStreamReader(
2105: trackbackUrlConnection
2106: .getInputStream()));
2107: String line;
2108: StringBuffer status = new StringBuffer();
2109: while ((line = trackbackStatus.readLine()) != null) {
2110: status.append(line).append("\n");
2111: }
2112: trackbackUrlConnection.disconnect();
2113:
2114: if (_logger.isDebugEnabled()) {
2115: _logger.debug("Trackback status for ping to "
2116: + trackbackURL + ": "
2117: + status.toString());
2118: }
2119: } catch (IOException e) {
2120: if (_logger.isErrorEnabled()) {
2121: _logger.error(e);
2122: }
2123: }
2124: }
2125: }
2126: }
2127: }
|