1 package org.roller.util; 2 3 import org.apache.commons.logging.Log; 4 import org.apache.commons.logging.LogFactory; 5 import org.roller.business.ThreadManagerImpl; 6 import org.roller.model.RollerFactory; 7 import org.roller.model.ThreadManager; 8 import org.roller.pojos.CommentData; 9 10 14 public class CommentSpamChecker 15 { 16 private static Log mLogger = LogFactory.getLog(CommentSpamChecker.class); 17 private Blacklist blacklist = Blacklist.getBlacklist(null,null); 18 19 23 public void testComment(CommentData comment) 24 { 25 try 26 { 27 boolean isSpam = blacklist.isBlacklisted(comment.getUrl()); 32 isSpam = blacklist.isBlacklisted(comment.getContent())?true:isSpam; 33 isSpam = blacklist.isBlacklisted(comment.getEmail())?true:isSpam; 34 35 if (isSpam) 36 { 37 comment.setSpam(Boolean.TRUE); 38 comment.save(); 39 RollerFactory.getRoller().commit(); 40 } 41 } 42 catch (Exception e) 43 { 44 mLogger.error("Processing Comment",e); 45 } 46 finally 47 { 48 RollerFactory.getRoller().release(); 49 } 50 } 51 52 56 public void testComment(CommentData comment, ThreadManager threadMgr) 57 { 58 try 59 { 60 if (threadMgr != null) 61 { 62 threadMgr.executeInBackground(new CommentCheckerRunnable(comment)); 63 } 64 else 65 { 66 mLogger.warn("No thread manager found."); 67 } 68 } 69 catch (InterruptedException e) { 70 mLogger.warn("Interrupted during Comment Spam check",e); 71 } 72 } 73 74 78 private class CommentCheckerRunnable implements Runnable 79 { 80 private CommentData mComment = null; 81 public CommentCheckerRunnable( CommentData comment) 82 { 83 mComment = comment; 84 } 85 public void run() 86 { 87 testComment(mComment); 88 } 89 } 90 } | Popular Tags |