01: /**
02: *
03: */package org.mortbay.cometd;
04:
05: import java.io.IOException;
06: import java.util.List;
07: import java.util.Map;
08:
09: import javax.servlet.http.HttpServletResponse;
10:
11: import org.mortbay.util.MultiPartWriter;
12:
13: public class MultiPartTransport extends AbstractTransport {
14: MultiPartWriter _writer;
15:
16: public void setResponse(HttpServletResponse response)
17: throws IOException {
18: super .setResponse(response);
19: response.setCharacterEncoding("utf-8");
20: _writer = new MultiPartWriter(response.getWriter());
21: response
22: .setContentType(MultiPartWriter.MULTIPART_X_MIXED_REPLACE
23: + "; boundary=" + _writer.getBoundary());
24:
25: }
26:
27: public void send(Map reply) throws IOException {
28: if (reply != null) {
29: _writer.startPart("text/plain; charset=utf-8");
30: _writer.write(JSON.toString(reply));
31: _writer.flush();
32: }
33: }
34:
35: public void send(List replies) throws IOException {
36: if (replies != null) {
37: _writer.startPart("text/plain; charset=utf-8");
38: _writer.write(JSON.toString(replies));
39: _writer.endPart();
40: _writer.flush();
41: }
42: }
43:
44: public void complete() throws IOException {
45: _writer.close();
46: }
47:
48: public boolean keepAlive() throws IOException {
49: _writer.startPart("text/plain; charset=utf-8");
50: _writer.write("{}");
51: _writer.flush();
52: return false;
53: }
54: }
|