comment.setNotify(new Boolean(commentRequest.isNotify()));
comment.setWeblogEntry(entry);
comment.setRemoteHost(request.getRemoteHost());
comment.setPostTime(new Timestamp(System.currentTimeMillis()));
WeblogEntryCommentForm cf = new WeblogEntryCommentForm();
cf.setData(comment);
// check if site is allowing comments
if(!RollerRuntimeConfig.getBooleanProperty("users.comments.enabled")) {
// TODO: i18n
error = "Comments are disabled for this site.";
// check if weblog and entry are allowing comments
} else if(!weblog.getAllowComments().booleanValue() ||
!entry.getCommentsStillAllowed()) {
// TODO: i18n
error = "Comments not allowed on this entry";
// make sure comment authentication passed
} else if(!this.authenticator.authenticate(request)) {
error = bundle.getString("error.commentAuthFailed");
log.debug("Comment failed authentication");
}
// bail now if we have already found an error
if(error != null) {
cf.setError(error);
request.setAttribute("commentForm", cf);
RequestDispatcher dispatcher = request.getRequestDispatcher(dispatch_url);
dispatcher.forward(request, response);
return;
}
if (preview) {
// TODO: i18n
message = "This is a comment preview only";
cf.setPreview(comment);
// If comment contains blacklisted text, warn commenter
SpamChecker checker = new SpamChecker();
if (checker.checkComment(comment)) {
error = bundle.getString("commentServlet.previewMarkedAsSpam");
log.debug("Comment marked as spam");
}
log.debug("Comment is a preview");
} else {
// If comment contains blacklisted text, mark as spam
SpamChecker checker = new SpamChecker();
if (checker.checkComment(comment)) {
comment.setSpam(Boolean.TRUE);
error = bundle.getString("commentServlet.commentMarkedAsSpam");
log.debug("Comment marked as spam");
}
// If comment moderation is on, set comment as pending
if (weblog.getCommentModerationRequired()) {
comment.setPending(Boolean.TRUE);
comment.setApproved(Boolean.FALSE);
message = bundle.getString("commentServlet.submittedToModerator");
} else {
comment.setPending(Boolean.FALSE);
comment.setApproved(Boolean.TRUE);
}
try {
WeblogManager mgr = RollerFactory.getRoller().getWeblogManager();
mgr.saveComment(comment);
RollerFactory.getRoller().flush();
reindexEntry(entry);
// Clear all caches associated with comment
CacheManager.invalidate(comment);
// Send email notifications
String rootURL = RollerRuntimeConfig.getAbsoluteContextURL();
if (rootURL == null || rootURL.trim().length()==0) {
rootURL = RequestUtils.serverURL(request) + request.getContextPath();
}
sendEmailNotification(comment, rootURL);
// comment was successful, clear the comment form
cf = new WeblogEntryCommentForm();
} catch (RollerException re) {
log.error("Error saving comment", re);
error = re.getMessage();
}
}
// the work has been done, now send the user back to the entry page
if (error != null)
cf.setError(error);
if (message != null)
cf.setMessage(message);
request.setAttribute("commentForm", cf);
log.debug("comment processed, forwarding to "+dispatch_url);
RequestDispatcher dispatcher =
request.getRequestDispatcher(dispatch_url);