Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java,v diff -u -r1.5 -r1.6 --- lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java 7 Jun 2006 01:53:04 -0000 1.5 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/model/Chat.java 8 Jun 2006 02:09:01 -0000 1.6 @@ -35,8 +35,6 @@ import org.lamsfoundation.lams.contentrepository.RepositoryCheckedException; import org.lamsfoundation.lams.contentrepository.client.IToolContentHandler; import org.lamsfoundation.lams.tool.chat.service.ChatService; -import org.lamsfoundation.lams.usermanagement.dto.UserDTO; -import org.lamsfoundation.lams.web.util.AttributeNames; /** * @hibernate.class table="tl_lachat11_chat" @@ -71,6 +69,10 @@ private Boolean lockOnFinished; + private Boolean filteringEnabled; + + private String filterKeywords; + private String onlineInstructions; private String offlineInstructions; @@ -97,6 +99,7 @@ /** full constructor */ public Chat(Date createDate, Date updateDate, Long createBy, String title, String instructions, Boolean runOffline, Boolean lockOnFinished, + Boolean filteringEnabled, String filterKeywords, String onlineInstructions, String offlineInstructions, Boolean contentInUse, Boolean defineLater, Long toolContentId, Set chatAttachments, Set chatSessions) { @@ -107,6 +110,8 @@ this.instructions = instructions; this.runOffline = runOffline; this.lockOnFinished = lockOnFinished; + this.filteringEnabled = filteringEnabled; + this.filterKeywords = filterKeywords; this.onlineInstructions = onlineInstructions; this.offlineInstructions = offlineInstructions; this.contentInUse = contentInUse; @@ -317,6 +322,28 @@ } /** + * @hibernate.property column="filtering_enabled" length="1" + */ + public Boolean getFilteringEnabled() { + return filteringEnabled; + } + + public void setFilteringEnabled(Boolean filteringEnabled) { + this.filteringEnabled = filteringEnabled; + } + + /** + * @hibernate.property column="filter_keywords" length="65535" + */ + public String getFilterKeywords() { + return filterKeywords; + } + + public void setFilterKeywords(String filterKeywords) { + this.filterKeywords = filterKeywords; + } + + /** * toString * * @return String @@ -380,13 +407,15 @@ Set set = new HashSet(); while (iter.hasNext()) { ChatAttachment originalFile = (ChatAttachment) iter.next(); - ChatAttachment newFile = (ChatAttachment) originalFile.clone(); - if(toolContentHandler != null){ - //duplicate file node in repository - NodeKey keys = toolContentHandler.copyFile(originalFile.getFileUuid()); + ChatAttachment newFile = (ChatAttachment) originalFile + .clone(); + if (toolContentHandler != null) { + // duplicate file node in repository + NodeKey keys = toolContentHandler.copyFile(originalFile + .getFileUuid()); newFile.setFileUuid(keys.getUuid()); newFile.setFileVersionId(keys.getVersion()); - } + } set.add(newFile); } chat.chatAttachments = set; Index: lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatMessageFilter.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatMessageFilter.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_chat/src/java/org/lamsfoundation/lams/tool/chat/util/ChatMessageFilter.java 8 Jun 2006 02:17:19 -0000 1.1 @@ -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; + } +}