You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2006/02/09 03:55:24 UTC
svn commit: r376156 - in /incubator/roller/trunk/src/org/roller/presentation:
servlets/CommentServlet.java servlets/TrackbackServlet.java
weblog/actions/CommentManagementAction.java
Author: snoopdave
Date: Wed Feb 8 18:55:23 2006
New Revision: 376156
URL: http://svn.apache.org/viewcvs?rev=376156&view=rev
Log:
Fixes ROL-1032: confirmation message when moderated comment is submitted
Modified:
incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java
incubator/roller/trunk/src/org/roller/presentation/servlets/TrackbackServlet.java
incubator/roller/trunk/src/org/roller/presentation/weblog/actions/CommentManagementAction.java
Modified: incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java?rev=376156&r1=376155&r2=376156&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/servlets/CommentServlet.java Wed Feb 8 18:55:23 2006
@@ -215,7 +215,12 @@
CacheManager.invalidate(comment);
// Send email notifications
- sendEmailNotification(request, rreq, entry, comment);
+ RollerContext rc = RollerContext.getRollerContext();
+ String rootURL = rc.getAbsoluteContextUrl(request);
+ if (rootURL == null || rootURL.trim().length()==0) {
+ rootURL = RequestUtils.serverURL(request) + request.getContextPath();
+ }
+ sendEmailNotification(comment, rootURL);
} else {
error = bundle.getString("error.commentAuthFailed");
@@ -270,16 +275,12 @@
*
* TODO: Make the addressing options configurable on a per-website basis.
*/
- static void sendEmailNotification(HttpServletRequest request,
- RollerRequest rreq,
- WeblogEntryData entry,
- CommentData cd)
- throws MalformedURLException {
-
- RollerContext rc = RollerContext.getRollerContext();
- ResourceBundle resources = ResourceBundle.getBundle(
- "ApplicationResources",LanguageUtil.getViewLocale(request));
+ public static void sendEmailNotification(CommentData cd, String rootURL) {
+
+ // Send commment notifications in locale of server
+ ResourceBundle resources = ResourceBundle.getBundle("ApplicationResources");
+ WeblogEntryData entry = cd.getWeblogEntry();
WebsiteData site = entry.getWebsite();
UserData user = entry.getCreator();
@@ -365,12 +366,7 @@
: "<br /><br /><hr /><span style=\"font-size: 11px\">");
msg.append(resources.getString("email.comment.respond") + ": ");
msg.append((escapeHtml) ? "\n" : "<br />");
-
- String rootURL = rc.getAbsoluteContextUrl(request);
- if (rootURL == null || rootURL.trim().length()==0) {
- rootURL = RequestUtils.serverURL(request) + request.getContextPath();
- }
-
+
// Build link back to comment
StringBuffer commentURL = new StringBuffer(rootURL);
commentURL.append(entry.getPermaLink());
@@ -436,6 +432,78 @@
sendMessage(session, from, new String[]{user.getEmailAddress()}, cc, bcc, subject,
ownermsg.toString(), isHtml);
}
+ } catch (javax.naming.NamingException ne) {
+ mLogger.error("Unable to lookup mail session. Check configuration. NamingException: " + ne.getMessage());
+ } catch (Exception e) {
+ mLogger.warn("Exception sending comment mail: " + e.getMessage());
+ // This will log the stack trace if debug is enabled
+ if (mLogger.isDebugEnabled()) {
+ mLogger.debug(e);
+ }
+ }
+
+ mLogger.debug("Done sending email message");
+
+ } // if email enabled
+ }
+
+ /**
+ * Send message to author of approved comment
+ *
+ * TODO: Make the addressing options configurable on a per-website basis.
+ */
+ public static void sendEmailApprovalNotification(CommentData cd, String rootURL) {
+
+ // Send commment notifications in locale of server
+ ResourceBundle resources = ResourceBundle.getBundle("ApplicationResources");
+
+ WeblogEntryData entry = cd.getWeblogEntry();
+ WebsiteData site = entry.getWebsite();
+ UserData user = entry.getCreator();
+
+ // Only send email if email notificaiton is enabled
+ boolean notify = RollerRuntimeConfig.getBooleanProperty("users.comments.emailnotify");
+ if (notify && site.getEmailComments().booleanValue()) {
+ mLogger.debug("Comment notification enabled ... preparing email");
+
+
+
+ //------------------------------------------
+ // --- Determine the "from" address
+ // --- Use either the site configured from address or the user's address
+
+ String from =
+ (StringUtils.isEmpty(site.getEmailFromAddress()))
+ ? user.getEmailAddress()
+ : site.getEmailFromAddress();
+
+ //------------------------------------------
+ // --- Form the message to be sent -
+
+ String subject = resources.getString("email.comment.commentApproved");
+
+ StringBuffer msg = new StringBuffer();
+ msg.append(resources.getString("email.comment.commentApproved"));
+
+ // Build link back to comment
+ StringBuffer commentURL = new StringBuffer(rootURL);
+ commentURL.append(entry.getPermaLink());
+ commentURL.append("#comments");
+ msg.append(commentURL.toString());
+
+ //------------------------------------------
+ // --- Send message to author of approved comment
+ try {
+ javax.naming.Context ctx = (javax.naming.Context)
+ new InitialContext().lookup("java:comp/env");
+ Session session = (Session)ctx.lookup("mail/Session");
+ String[] cc = null;
+ String[] bcc = null;
+ sendMessage(session, from,
+ new String[] {cd.getEmail()},
+ null, // cc
+ null, // bcc
+ subject, msg.toString(), false);
} catch (javax.naming.NamingException ne) {
mLogger.error("Unable to lookup mail session. Check configuration. NamingException: " + ne.getMessage());
} catch (Exception e) {
Modified: incubator/roller/trunk/src/org/roller/presentation/servlets/TrackbackServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/servlets/TrackbackServlet.java?rev=376156&r1=376155&r2=376156&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/servlets/TrackbackServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/servlets/TrackbackServlet.java Wed Feb 8 18:55:23 2006
@@ -15,6 +15,7 @@
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.struts.util.RequestUtils;
import org.roller.config.RollerRuntimeConfig;
import org.roller.pojos.CommentData;
import org.roller.util.SpamChecker;
@@ -191,7 +192,12 @@
CacheManager.invalidate(comment);
// Send email notifications
- CommentServlet.sendEmailNotification(req, rreq, entry, comment);
+ RollerContext rc = RollerContext.getRollerContext();
+ String rootURL = rc.getAbsoluteContextUrl(req);
+ if (rootURL == null || rootURL.trim().length()==0) {
+ rootURL = RequestUtils.serverURL(req) + req.getContextPath();
+ }
+ CommentServlet.sendEmailNotification(comment, rootURL);
pw.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
pw.println("<response>");
Modified: incubator/roller/trunk/src/org/roller/presentation/weblog/actions/CommentManagementAction.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/weblog/actions/CommentManagementAction.java?rev=376156&r1=376155&r2=376156&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/weblog/actions/CommentManagementAction.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/weblog/actions/CommentManagementAction.java Wed Feb 8 18:55:23 2006
@@ -1,6 +1,7 @@
package org.roller.presentation.weblog.actions;
import java.io.IOException;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@@ -18,6 +19,7 @@
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.actions.DispatchAction;
+import org.apache.struts.util.RequestUtils;
import org.roller.RollerException;
import org.roller.model.Roller;
import org.roller.model.RollerFactory;
@@ -25,9 +27,11 @@
import org.roller.pojos.CommentData;
import org.roller.pojos.WeblogEntryData;
import org.roller.presentation.BasePageModel;
+import org.roller.presentation.RollerContext;
import org.roller.presentation.RollerRequest;
import org.roller.presentation.RollerSession;
import org.roller.presentation.cache.CacheManager;
+import org.roller.presentation.servlets.CommentServlet;
import org.roller.presentation.weblog.formbeans.CommentManagementForm;
import org.roller.util.Utilities;
@@ -118,7 +122,12 @@
List deletedList = Arrays.asList(deleteIds);
if (deleteIds != null && deleteIds.length > 0) {
mgr.removeComments(deleteIds);
- }
+ }
+
+ // Collect comments approved for first time, so we can send
+ // out comment approved notifications later
+ List approvedComments = new ArrayList();
+
// loop through IDs of all comments displayed on page
String[] ids = Utilities.stringToStringArray(queryForm.getIds(),",");
List flushList = new ArrayList();
@@ -141,13 +150,17 @@
if (rreq.getWebsite() != null) {
// all comments reviewed, so they're no longer pending
- comment.setPending(Boolean.FALSE);
+ if (comment.getPending() != null && comment.getPending().booleanValue()) {
+ comment.setPending(Boolean.FALSE);
+ approvedComments.add(comment);
+ }
// apply pending checkbox
List approvedIds =
Arrays.asList(queryForm.getApprovedComments());
if (approvedIds.contains(ids[i])) {
comment.setApproved(Boolean.TRUE);
+
} else {
comment.setApproved(Boolean.FALSE);
}
@@ -159,6 +172,9 @@
for (Iterator comments=flushList.iterator(); comments.hasNext();) {
CacheManager.invalidate((CommentData)comments.next());
}
+
+ sendCommentNotifications(request, approvedComments);
+
ActionMessages msgs = new ActionMessages();
msgs.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("commentManagement.updateSuccess"));
@@ -182,6 +198,32 @@
return mapping.findForward("commentManagement.page");
}
return mapping.findForward("commentManagementGlobal.page");
+ }
+
+ private void sendCommentNotifications(
+ HttpServletRequest req, List comments) throws RollerException {
+
+ RollerContext rc = RollerContext.getRollerContext();
+ String rootURL = rc.getAbsoluteContextUrl(req);
+ try {
+ if (rootURL == null || rootURL.trim().length()==0) {
+ rootURL = RequestUtils.serverURL(req) + req.getContextPath();
+ }
+ } catch (MalformedURLException e) {
+ logger.error("ERROR: determining URL of site");
+ return;
+ }
+
+ Iterator iter = comments.iterator();
+ while (iter.hasNext()) {
+ CommentData comment = (CommentData)iter.next();
+
+ // Send email notifications because a new comment has been approved
+ CommentServlet.sendEmailNotification(comment, rootURL);
+
+ // Send approval notification to author of approved comment
+ CommentServlet.sendEmailApprovalNotification(comment, rootURL);
+ }
}
public class CommentManagementPageModel extends BasePageModel {