throw new WebloggerException("unable to lookup weblog: "+
trackbackRequest.getWeblogHandle());
}
// lookup entry specified by comment request
WeblogEntryManager weblogMgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
entry = weblogMgr.getWeblogEntryByAnchor(weblog, trackbackRequest.getWeblogAnchor());
if (entry == null) {
throw new WebloggerException("unable to lookup entry: "+
trackbackRequest.getWeblogAnchor());
}
} catch (Exception e) {
// some kind of error parsing the request or looking up weblog
logger.debug("error creating trackback request", e);
error = e.getMessage();
}
}
if (error != null) {
pw.println(this.getErrorResponse(error));
return;
}
try {
// check if trackbacks are allowed for this entry
// this checks site-wide settings, weblog settings, and entry settings
if (entry != null && entry.getCommentsStillAllowed() && entry.isPublished()) {
// Track trackbacks as comments
WeblogEntryComment comment = new WeblogEntryComment();
comment.setContent("[Trackback] "+trackbackRequest.getExcerpt());
comment.setName(trackbackRequest.getBlogName());
comment.setUrl(trackbackRequest.getUrl());
comment.setWeblogEntry(entry);
comment.setRemoteHost(request.getRemoteHost());
comment.setNotify(Boolean.FALSE);
comment.setPostTime(new Timestamp(new Date().getTime()));
// run new trackback through validators
int validationScore = commentValidationManager.validateComment(comment, messages);
logger.debug("Comment Validation score: " + validationScore);
if (validationScore == 100 && weblog.getCommentModerationRequired()) {
// Valid comments go into moderation if required
comment.setStatus(WeblogEntryComment.PENDING);
} else if (validationScore == 100) {
// else they're approved
comment.setStatus(WeblogEntryComment.APPROVED);
} else {
// Invalid comments are marked as spam
comment.setStatus(WeblogEntryComment.SPAM);
}
// save, commit, send response
if(!WeblogEntryComment.SPAM.equals(comment.getStatus()) ||
!WebloggerRuntimeConfig.getBooleanProperty("trackbacks.ignoreSpam.enabled")) {
WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
mgr.saveComment(comment);
WebloggerFactory.getWeblogger().flush();
// only invalidate the cache if comment isn't moderated
if(!weblog.getCommentModerationRequired()) {
// Clear all caches associated with comment