01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.dwrp;
17:
18: import java.io.IOException;
19:
20: import javax.servlet.http.HttpServletResponse;
21:
22: import org.directwebremoting.ScriptBuffer;
23: import org.directwebremoting.extend.ConverterManager;
24: import org.directwebremoting.extend.MarshallException;
25: import org.directwebremoting.extend.ScriptBufferUtil;
26: import org.directwebremoting.util.MimeConstants;
27:
28: /**
29: * A ScriptConduit for use with plain Javascript output.
30: * <p>Scripts are plain Javascript without 'execute-in-parent-context' wrapping,
31: * but with script-start and script-end markers.
32: * <p>If this conduit is used the client should direct the output to an iframe
33: * and then poll, looking for new data into the iframe. The html tags should be
34: * removed and script between script-start and script-end tags eval()ed.
35: * <p>This conduit is useful for Firefox. It will not work as it stands with IE
36: * 6/6 because they don't allow the browser to see data entering an iframe until
37: * it overflows a 4k buffer. See the {@link Html4kScriptConduit} for a version
38: * that works around this problem.
39: * @author Joe Walker [joe at getahead dot ltd dot uk]
40: */
41: public class PlainScriptConduit extends BaseScriptConduit {
42: /**
43: * Simple ctor
44: * @param response Used to flush output
45: * @param batchId The id of the batch that we are responding to
46: * @param converterManager How we convert objects to script
47: * @throws IOException If stream actions fail
48: */
49: public PlainScriptConduit(HttpServletResponse response,
50: String batchId, ConverterManager converterManager,
51: boolean jsonOutput) throws IOException {
52: super (response, batchId, converterManager, jsonOutput);
53: }
54:
55: /* (non-Javadoc)
56: * @see org.directwebremoting.dwrp.BaseScriptConduit#preStreamSetup()
57: */
58: @Override
59: protected String getOutboundMimeType() {
60: return MimeConstants.MIME_JS;
61: }
62:
63: /* (non-Javadoc)
64: * @see org.directwebremoting.dwrp.BaseScriptConduit#beginStream()
65: */
66: @Override
67: public void beginStream() {
68: }
69:
70: /* (non-Javadoc)
71: * @see org.directwebremoting.dwrp.BaseScriptConduit#endStream()
72: */
73: @Override
74: public void endStream() {
75: }
76:
77: /* (non-Javadoc)
78: * @see org.directwebremoting.ScriptConduit#addScript(org.directwebremoting.ScriptBuffer)
79: */
80: @Override
81: public boolean addScript(ScriptBuffer scriptBuffer)
82: throws IOException, MarshallException {
83: String script = ScriptBufferUtil.createOutput(scriptBuffer,
84: converterManager, jsonOutput);
85:
86: synchronized (out) {
87: out.println(ProtocolConstants.SCRIPT_START_MARKER);
88: out.println(script);
89: out.println(ProtocolConstants.SCRIPT_END_MARKER);
90:
91: return flush();
92: }
93: }
94: }
|