1 package chat.presentation; 2 3 import chat.ChatApplication; 4 import chat.spec.*; 5 6 import java.io.IOException ; 8 9 import com.lutris.appserver.server.httpPresentation.HttpPresentation; 11 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms; 12 import com.lutris.appserver.server.httpPresentation.HttpPresentationException; 13 import com.lutris.util.KeywordValueException; 14 15 import org.w3c.dom.html.HTMLBodyElement; 16 import org.w3c.dom.html.HTMLElement; 17 import org.w3c.dom.Node ; 18 import org.w3c.dom.html.HTMLFontElement; 19 20 public class EntryFormPresentation implements HttpPresentation { 21 22 private static EntryFormHTML entryForm; 23 24 public void run(HttpPresentationComms comms) throws HttpPresentationException, IOException { 25 try{ 26 maybeAddMsg(comms); 27 fillInFields(comms); 28 }catch(Exception e){ 29 e.printStackTrace(); 30 } 31 32 } 33 34 43 static public void maybeAddMsg(HttpPresentationComms comms) throws Exception { 44 ChatApplication myApp = (ChatApplication) comms.application; 45 String name = comms.request.getParameter("userName"); 46 47 if (name == null) 48 return; 49 String text = comms.request.getParameter("text"); 50 if (text == null) 51 return; 52 String clearCmd = myApp.getClearCommand(); 53 54 DiscussionManager discussionManager = DiscussionManagerFactory.getDiscussionManager("chat.business.DiscussionManagerImpl"); 55 56 61 try{ 62 if ((clearCmd.length() != 0) && text.equals(clearCmd)) 63 discussionManager.clear(); 64 else 65 discussionManager.addMessage(name, text); 66 }catch(NullPointerException ex){} 67 } 68 69 72 static public void fillInFields(HttpPresentationComms comms) throws Exception { 73 ChatApplication myApp = (ChatApplication) comms.application; 74 String name = comms.request.getParameter("userName"); 75 76 entryForm = (EntryFormHTML)comms.xmlcFactory.create(EntryFormHTML.class); 78 HTMLBodyElement color = entryForm.getElementColor(); 79 color.setBgColor(myApp.getBgColor()); 80 comms.response.writeDOM(entryForm); 81 82 86 String message = "Reload the page if your messages stop appearing."; 87 String ua = comms.request.getHeader("User-Agent"); 88 if ((ua == null) || (ua.indexOf("MSIE") == -1)) 89 message += "<br>It is normal for the page to " + 90 "keep loading indefinitely."; 91 message += "<br>This is a demonstration <a HREF=http://www.enhydra.org " + 92 "target=enhydra>Enhydra</a> application."; 93 entryForm.setTextMessage(message); 94 comms.response.writeDOM(entryForm); 95 96 } 97 98 } 99 100 101 102 | Popular Tags |