1 26 27 package chat.presentation; 28 29 import java.util.Vector ; 30 import com.lutris.appserver.server.httpPresentation.*; 31 import chat.ChatApplication; 32 import chat.spec.*; 33 34 39 public class ContentsPresentation implements HttpPresentation { 40 41 45 private static final int refreshWait = 60; 46 47 55 private static long counter = 0; 56 57 58 61 public void run(HttpPresentationComms comms) throws Exception { 62 long state = 0; 64 try { 65 String stateStr = comms.request.getParameter("state"); 66 if (stateStr != null) 67 state = Long.parseLong(stateStr); 68 } catch (Exception e) { 69 } 70 long wait = 0; 72 try { 73 String waitStr = comms.request.getParameter("wait"); 74 if (waitStr != null) 75 wait = Long.parseLong(waitStr); 76 } catch (Exception e) { 77 } 78 81 82 DiscussionManager discussionManager = DiscussionManagerFactory.getDiscussionManager("chat.business.DiscussionManagerImpl"); 83 84 85 86 87 88 89 90 93 ChatApplication myApp = (ChatApplication) comms.application; 94 95 comms.response.setContentType("text/html"); 96 comms.response.setHeader("Expires", "Tue, 01 Jan 1980 1:00:00 GMT"); 97 comms.response.setHeader("Pragma", "no-cache"); 98 HttpPresentationOutputStream out = comms.response.getOutputStream(); 99 100 out.println("<HTML>"); 101 out.println("<HEAD></HEAD>"); 102 out.println("<BODY onload=\"loadOn();\" BGCOLOR=" + myApp.getBgColor() +">"); 103 out.println("<h3><center><font color=purple>" + 104 myApp.getRoomName() + 105 "</font></center></h3>"); 106 107 112 113 try{ 114 Snapshot snap = discussionManager.getContents(state, wait); 115 116 if ((snap.getContents() == null) || (snap.getContents().size() == 0)) { 117 out.println("<center><i><br><br><br><font color=purple><b>" + 118 "There are currently no messages." + 119 "</b></font></i></center>\n"); 120 } else { 121 for (int i=snap.getContents().size()-1; i>=0; i--) { 122 129 130 Message msg = (Message) snap.getContents().elementAt(i); 131 132 if (msg == null) 133 continue; 134 out.print("<b>"); 135 if ((msg.getHtmlName() == null) || (msg.getHtmlName().length() == 0)) 136 out.print("<i>Anonymous</i>"); 137 else 138 out.print(msg.getHtmlName()); 139 out.print(":</b> "); 140 if (msg.getHtmlChunks().size() > 1) 141 out.print("<br>\n "); 142 for (int j=0; j<((Vector )msg.getHtmlChunks()).size(); j++) { 143 if (j != 0) 144 out.print(" "); 145 out.print((String ) ((Vector )msg.getHtmlChunks()).elementAt(j)); 146 out.println("<br>"); 147 } 148 } 149 } 150 151 152 160 161 out.println("<SCRIPT TYPE=\"text/javascript\" LANGUAGE=\"JavaScript\" id=\"RealScript\">\n" 162 + "<!--\n" 163 + " function loadOn() {\n" 164 + " window.location.href = \"ContentsPresentation.po?state=" + snap.getState() + "&wait=" + refreshWait + "&uniqe=" + counter +"\"\n" 165 + " }\n" 166 + "//-->\n" 167 + "</SCRIPT>"); 168 169 }catch(NullPointerException e){} 170 173 out.println("</BODY>"); 174 out.println("</HTML>"); 175 } 176 177 } 178 179 | Popular Tags |