// just send back a 404 - this is probably somebody looking for a way
// to send comment spam ;-)
log.info("ignoring saveComment with no related blog entry (spam) from " + request.getRemoteAddr());
return new NotFoundView();
} else if (!blogEntry.isCommentsEnabled()) {
return new CommentConfirmationView();
}
comment = createComment(request, blogEntry);
ValidationContext context = validateComment(comment);
// are we previewing or adding the comment?
String previewButton = I18n.getMessage(blog, "comment.previewButton");
ContentDecoratorContext decoratorContext = new ContentDecoratorContext();
decoratorContext.setView(ContentDecoratorContext.DETAIL_VIEW);
decoratorContext.setMedia(ContentDecoratorContext.HTML_PAGE);
Comment decoratedComment = (Comment)comment.clone();
blog.getContentDecoratorChain().decorate(decoratorContext, decoratedComment);
getModel().put("decoratedComment", decoratedComment);
getModel().put("undecoratedComment", comment);
getModel().put("rememberMe", rememberMe);
getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
getModel().put(Constants.COMMENT_KEY, comment);
request.getSession().setAttribute("rememberMe", request.getParameter("rememberMe"));
if (submitType == null || submitType.equalsIgnoreCase(previewButton) || context.hasErrors()) {
return new CommentFormView();
} else {
CommentConfirmationStrategy strategy = blog.getCommentConfirmationStrategy();
Comment clonedComment = (Comment)comment.clone();
request.getSession().setAttribute(Constants.COMMENT_KEY, comment);
if (strategy.confirmationRequired(clonedComment)) {
strategy.setupConfirmation(request);
return new ConfirmCommentView();
} else {
try {
saveComment(request, response, blogEntry, comment);
request.getSession().removeAttribute(Constants.COMMENT_KEY);
return new CommentConfirmationView();
} catch (BlogServiceException be) {
log.error(be.getMessage(), be);
throw new ServletException(be);
}
}