*/
public String update() {
if (!"POST".equals(httpMethod)) return ERROR;
try {
WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
List<Weblog> flushList = new ArrayList<Weblog>();
// delete all comments with delete box checked
List<String> deletes = Arrays.asList(getBean().getDeleteComments());
if(deletes != null && deletes.size() > 0) {
log.debug("Processing deletes - "+deletes.size());
WeblogEntryComment deleteComment = null;
for(String deleteId : deletes) {
deleteComment = wmgr.getComment(deleteId);
flushList.add(deleteComment.getWeblogEntry().getWebsite());
wmgr.removeComment(deleteComment);
}
}
// loop through IDs of all comments displayed on page
List spamIds = Arrays.asList(getBean().getSpamComments());
log.debug(spamIds.size()+" comments marked as spam");
String[] ids = Utilities.stringToStringArray(getBean().getIds(),",");
for (int i=0; i < ids.length; i++) {
log.debug("processing id - "+ ids[i]);
// if we already deleted it then skip forward
if(deletes.contains(ids[i])) {
log.debug("Already deleted, skipping - "+ids[i]);
continue;
}
WeblogEntryComment comment = wmgr.getComment(ids[i]);
// mark/unmark spam
if (spamIds.contains(ids[i]) &&
!WeblogEntryComment.SPAM.equals(comment.getStatus())) {
log.debug("Marking as spam - "+comment.getId());
comment.setStatus(WeblogEntryComment.SPAM);
wmgr.saveComment(comment);
flushList.add(comment.getWeblogEntry().getWebsite());
} else if(WeblogEntryComment.SPAM.equals(comment.getStatus())) {
log.debug("Marking as approved - "+comment.getId());
comment.setStatus(WeblogEntryComment.APPROVED);
wmgr.saveComment(comment);
flushList.add(comment.getWeblogEntry().getWebsite());
}
}