Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatMessageFilter.java =================================================================== diff -u --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatMessageFilter.java (revision 0) +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatMessageFilter.java (revision 3f2f66ee045baee864813b60e960478908341832) @@ -0,0 +1,57 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ + +package org.lamsfoundation.lams.tool.chat.util; + +import java.util.regex.Pattern; + +import org.lamsfoundation.lams.tool.chat.model.Chat; + +public class ChatMessageFilter { + + private Pattern pattern; + + public ChatMessageFilter(Chat chat) { + this.pattern = null; + String regex = chat.getFilterKeywords(); + if (regex != null) { + // constructing regex + regex = regex.replaceAll("[" + "\\(" + "\\)" + "\\[" + "\\]" + + "\\{" + "\\}" + "\\\\" + "\\^" + "\\$" + "\\|" + "\\?" + + "\\*" + "\\+" + "\\." + "]+", " "); + regex = regex.replaceAll("[\\s]+", " "); + regex = regex.trim(); + regex = regex.replaceAll(" ", "|"); + + if (regex.length() != 0) { + this.pattern = Pattern.compile(regex); + } + } + } + + public Pattern getPattern() { + return this.pattern; + } +}