Source code: com/acme/gui/presObjs/StreamPO.java
1 /*
2 * Enhydra Java Application Server Project
3 *
4 * The contents of this file are subject to the Enhydra Public License
5 * Version 1.1 (the "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy of the License on
7 * the Enhydra web site ( http://www.enhydra.org/ ).
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11 * the License for the specific terms governing rights and limitations
12 * under the License.
13 *
14 * The Initial Developer of the Enhydra Application Server is Lutris
15 * Technologies, Inc. The Enhydra Application Server and portions created
16 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17 * All Rights Reserved.
18 *
19 * Contributor(s):
20 *
21 * $Id: StreamPO.java,v 1.10.10.1 2000/10/19 17:59:06 jasona Exp $
22 */
23
24
25
26
27 /*
28 * Test presentation object to send a stream of JavaScript tags to the
29 * browers. This is used as a test of streaming data. It write to a single
30 * frame.
31 *
32 * Expected arguments are:
33 * frame=name
34 * N.B. jolt was not used since we don't want a dependency in these tests.
35 */
36 package com.acme.gui.presObjs;
37
38 import com.lutris.appserver.server.httpPresentation.*;
39
40
41 public class StreamPO implements HttpPresentation {
42
43 private static boolean stop = false;
44
45 private String getParam (HttpPresentationComms comms,
46 String name)
47 throws HttpPresentationException {
48 String param = comms.request.getParameter(name);
49 if (param == null) {
50 throw new HttpPresentationException("Required argument \"" +
51 name + "\" not specified");
52 }
53 return param;
54 }
55
56 private void wasteTime(int factor) {
57 String str = "";
58 for (int cnt = 0; cnt < factor; cnt++) {
59 str = str + "A";
60 }
61 }
62
63
64 private void updateFrameText(HttpPresentationOutputStream out,
65 String frame,
66 String text)
67 throws java.io.IOException {
68 out.println("<SCRIPT LANGUAGE=\"Javascript\">");
69 if (false) {
70 out.println("parent." + frame + ".document.open()");
71 out.println("parent." + frame + ".document.write(\"" + text + "\")");
72 out.println("parent." + frame + ".document.close()");
73 }
74 out.println("document.msgBox.msg.value=\"" + text + "\"");
75 out.println("</SCRIPT>");
76 out.flush();
77 }
78
79 public void run(HttpPresentationComms comms) throws Exception {
80 comms.response.setStatus(HttpPresentationResponse.SC_OK, "Good job");
81
82 HttpPresentationOutputStream out = comms.response.getOutputStream();
83
84 // Handle stop button; set global stop flag.
85 String stopRequest = comms.request.getParameter("stopButton");
86 if (stopRequest != null) {
87 out.println("<CENTER>Stopped</CENTER>\n");
88 stop = true;
89 return;
90 }
91
92
93 String frame = getParam(comms, "frame");
94 int maxUpdate = 1000;
95
96 stop = false;
97
98 out.println("<Center>\n");
99 out.println("<H2>Streaming Presentation Object " + frame + "</H2>\n");
100 out.println("<FORM NAME=\"msgBox\">");
101 out.println("<INPUT TYPE=\"text\" NAME=\"msg\" VALUE=\"Nothing yet\">");
102 out.println("</FORM>");
103 out.println("</Center>\n");
104 out.flush();
105
106 for (int cnt = 0; (cnt < maxUpdate) && (!stop); cnt++) {
107 updateFrameText(out, frame, "Frame " + frame + ", update " + cnt);
108 wasteTime(1000);
109 }
110
111 System.err.println("Exit PO");
112 }
113 }