1 package org.getahead.dwrdemo.chat; 2 3 import java.util.Collection ; 4 import java.util.LinkedList ; 5 6 import org.directwebremoting.WebContext; 7 import org.directwebremoting.WebContextFactory; 8 import org.directwebremoting.proxy.dwr.Util; 9 import org.directwebremoting.util.Logger; 10 11 14 public class JavaChat 15 { 16 19 public void addMessage(String text) 20 { 21 if (text != null && text.trim().length() > 0) 23 { 24 messages.addFirst(new Message(text)); 25 while (messages.size() > 10) 26 { 27 messages.removeLast(); 28 } 29 } 30 31 WebContext wctx = WebContextFactory.get(); 32 String currentPage = wctx.getCurrentPage(); 33 34 Util utilThis = new Util(wctx.getScriptSession()); 36 utilThis.setValue("text", ""); 37 38 Collection sessions = wctx.getScriptSessionsByPage(currentPage); 40 Util utilAll = new Util(sessions); 41 42 utilAll.removeAllOptions("chatlog"); 44 utilAll.addOptions("chatlog", messages, "text"); 45 } 46 47 50 private LinkedList messages = new LinkedList (); 51 52 55 protected static final Logger log = Logger.getLogger(JavaChat.class); 56 } 57 | Popular Tags |