IPBanList.getInstance().addBannedIp(request.getRemoteAddr());
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
WeblogCommentRequest commentRequest = null;
try {
commentRequest = new WeblogCommentRequest(request);
// lookup weblog specified by comment request
UserManager uMgr = WebloggerFactory.getWeblogger().getUserManager();
weblog = uMgr.getWebsiteByHandle(commentRequest.getWeblogHandle());
if(weblog == null) {
throw new WebloggerException("unable to lookup weblog: "+
commentRequest.getWeblogHandle());
}
// lookup entry specified by comment request
entry = commentRequest.getWeblogEntry();
if(entry == null) {
throw new WebloggerException("unable to lookup entry: "+
commentRequest.getWeblogAnchor());
}
// we know what the weblog entry is, so setup our urls
dispatch_url = "/roller-ui/rendering/page/"+weblog.getHandle();
if(commentRequest.getLocale() != null) {
dispatch_url += "/"+commentRequest.getLocale();
}
dispatch_url += "/entry/"+URLUtilities.encode(commentRequest.getWeblogAnchor());
} catch (Exception e) {
// some kind of error parsing the request or looking up weblog
log.debug("error creating page request", e);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
log.debug("Doing comment posting for entry = "+entry.getPermalink());
// collect input from request params and construct new comment object
// fields: name, email, url, content, notify
// TODO: data validation on collected comment data
WeblogEntryComment comment = new WeblogEntryComment();
comment.setName(commentRequest.getName());
comment.setEmail(commentRequest.getEmail());
comment.setUrl(commentRequest.getUrl());
comment.setContent(commentRequest.getContent());
comment.setNotify(new Boolean(commentRequest.isNotify()));
comment.setWeblogEntry(entry);
comment.setRemoteHost(request.getRemoteHost());
comment.setPostTime(new Timestamp(System.currentTimeMillis()));
// set comment content-type depending on if html is allowed
if(WebloggerRuntimeConfig.getBooleanProperty("users.comments.htmlenabled")) {
comment.setContentType("text/html");
} else {
comment.setContentType("text/plain");
}
// set whatever comment plugins are configured
comment.setPlugins(WebloggerRuntimeConfig.getProperty("users.comments.plugins"));
WeblogEntryCommentForm cf = new WeblogEntryCommentForm();
cf.setData(comment);
if (preview) {
cf.setPreview(comment);
}
I18nMessages messageUtils = I18nMessages.getMessages(commentRequest.getLocaleInstance());
// check if comments are allowed for this entry
// this checks site-wide settings, weblog settings, and entry settings
if(!entry.getCommentsStillAllowed() || !entry.isPublished()) {
error = messageUtils.getString("comments.disabled");