⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commentspamchecker.java

📁 这个weblogging 设计得比较精巧
💻 JAVA
字号:
package org.roller.util;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.roller.business.ThreadManagerImpl;import org.roller.model.RollerFactory;import org.roller.model.ThreadManager;import org.roller.pojos.CommentData;/** * Created on Mar 9, 2004 * @author lance.lavandowska */public class CommentSpamChecker{    private static Log mLogger = LogFactory.getLog(CommentSpamChecker.class);    private Blacklist blacklist = Blacklist.getBlacklist(null,null);    // -----------------------------------------------------------------------    /**     * Runs comment check on comment, sets spam flag on comment.     */    public void testComment(CommentData comment)    {        try        {            // by using the OR conditional it'll test each            // one in order and fall into the body without            // having to test each and every condition.            // Not sure which is the optimal order to check, though.            boolean isSpam = blacklist.isBlacklisted(comment.getUrl());            isSpam = blacklist.isBlacklisted(comment.getContent())?true:isSpam;            isSpam = blacklist.isBlacklisted(comment.getEmail())?true:isSpam;            if (isSpam)            {                comment.setSpam(Boolean.TRUE);                comment.save();                RollerFactory.getRoller().commit();            }        }        catch (Exception e)        {            mLogger.error("Processing Comment",e);        }        finally        {            RollerFactory.getRoller().release();        }    }        // -----------------------------------------------------------------------    /**     * Spawns thread to run comment check.     */    public void testComment(CommentData comment, ThreadManager threadMgr)    {        try        {            if (threadMgr != null)            {                threadMgr.executeInBackground(new CommentCheckerRunnable(comment));            }            else            {                mLogger.warn("No thread manager found.");            }        }         catch (InterruptedException e) {            mLogger.warn("Interrupted during Comment Spam check",e);        }    }    // -----------------------------------------------------------------------    /**     * Runnable to run spam check on it's own thread.     */    private class CommentCheckerRunnable implements Runnable    {        private CommentData mComment = null;        public CommentCheckerRunnable( CommentData comment)        {            mComment = comment;        }        public void run()        {            testComment(mComment);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -