1 31 package org.blojsom.plugin.comment; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.blojsom.blog.Blog; 36 import org.blojsom.blog.Entry; 37 import org.blojsom.plugin.Plugin; 38 import org.blojsom.plugin.PluginException; 39 40 import javax.servlet.http.HttpServletRequest ; 41 import javax.servlet.http.HttpServletResponse ; 42 import java.util.HashMap ; 43 import java.util.Map ; 44 45 52 public class CommentModerationPlugin implements Plugin { 53 54 private Log _logger = LogFactory.getLog(CommentModerationPlugin.class); 55 56 public static final String COMMENT_MODERATION_ENABLED = "comment-moderation-enabled"; 58 59 public static final String BLOJSOM_COMMENT_MODERATION_PLUGIN_APPROVED = "BLOJSOM_COMMENT_MODERATION_PLUGIN_APPROVED"; 61 62 65 public CommentModerationPlugin() { 66 } 67 68 74 public void init() throws PluginException { 75 } 76 77 88 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 89 moderateComment(httpServletRequest, httpServletResponse, blog, context, entries); 90 91 return entries; 92 } 93 94 104 protected void moderateComment(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 105 if ("true".equalsIgnoreCase(blog.getProperty(COMMENT_MODERATION_ENABLED))) { 106 if ("y".equalsIgnoreCase(httpServletRequest.getParameter(CommentPlugin.COMMENT_PARAM)) && blog.getBlogCommentsEnabled().booleanValue()) { 107 Map commentMetaData; 108 if (context.containsKey(CommentPlugin.BLOJSOM_PLUGIN_COMMENT_METADATA)) { 109 commentMetaData = (Map ) context.get(CommentPlugin.BLOJSOM_PLUGIN_COMMENT_METADATA); 110 } else { 111 commentMetaData = new HashMap (); 112 } 113 114 commentMetaData.put(BLOJSOM_COMMENT_MODERATION_PLUGIN_APPROVED, Boolean.FALSE.toString()); 115 context.put(CommentPlugin.BLOJSOM_PLUGIN_COMMENT_METADATA, commentMetaData); 116 117 if (_logger.isDebugEnabled()) { 118 _logger.debug("Marking comment as requiring approval"); 119 } 120 } 121 } 122 } 123 124 130 public void cleanup() throws PluginException { 131 } 132 133 139 public void destroy() throws PluginException { 140 } 141 } | Popular Tags |