KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > directwebremoting > dwrp > Html4kScriptConduit


1 /*
2  * Copyright 2005 Joe Walker
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21
22 import org.directwebremoting.ScriptBuffer;
23 import org.directwebremoting.extend.ConverterManager;
24 import org.directwebremoting.extend.EnginePrivate;
25 import org.directwebremoting.extend.MarshallException;
26 import org.directwebremoting.extend.ScriptBufferUtil;
27 import org.directwebremoting.util.MimeConstants;
28
29 /**
30  * A ScriptConduit for use with HTML wrapped Javascript output.
31  * @author Joe Walker [joe at getahead dot ltd dot uk]
32  */

33 public class Html4kScriptConduit extends BaseScriptConduit
34 {
35     /**
36      * Simple ctor
37      * @param response Used to flush output
38      * @param partialResponse Do we do the IE 4k flush hack
39      * @param batchId The id of the batch that we are responding to
40      * @param converterManager How we convert objects to script
41      * @throws IOException If stream ops fail
42      */

43     public Html4kScriptConduit(HttpServletResponse JavaDoc response, int partialResponse, String JavaDoc batchId, ConverterManager converterManager) throws IOException JavaDoc
44     {
45         super(response, batchId, converterManager);
46         this.partialResponse = partialResponse;
47     }
48
49     /* (non-Javadoc)
50      * @see org.directwebremoting.dwrp.BaseCallMarshaller#getOutboundMimeType()
51      */

52     protected String JavaDoc getOutboundMimeType()
53     {
54         return MimeConstants.MIME_HTML;
55     }
56
57     /* (non-Javadoc)
58      * @see org.directwebremoting.dwrp.BaseScriptConduit#beginStream()
59      */

60     public void beginStream()
61     {
62         synchronized (out)
63         {
64             out.println("<html><body><pre>");
65             out.println(ProtocolConstants.SCRIPT_START_MARKER);
66             out.println(EnginePrivate.remoteBeginIFrameResponse(batchId, false));
67             out.println(ProtocolConstants.SCRIPT_END_MARKER);
68         }
69     }
70
71     /* (non-Javadoc)
72      * @see org.directwebremoting.dwrp.BaseScriptConduit#endStream()
73      */

74     public void endStream()
75     {
76         synchronized (out)
77         {
78             out.println(EnginePrivate.remoteEndIFrameResponse(batchId, false));
79             out.println(ProtocolConstants.SCRIPT_START_MARKER);
80             out.println("</pre></body></html>");
81             out.println(ProtocolConstants.SCRIPT_END_MARKER);
82         }
83     }
84
85     /* (non-Javadoc)
86      * @see org.directwebremoting.ScriptConduit#addScript(org.directwebremoting.ScriptBuffer)
87      */

88     public boolean addScript(ScriptBuffer scriptBuffer) throws IOException JavaDoc, MarshallException
89     {
90         String JavaDoc script = ScriptBufferUtil.createOutput(scriptBuffer, converterManager);
91
92         synchronized (out)
93         {
94             out.println(ProtocolConstants.SCRIPT_START_MARKER);
95             out.println(script);
96             out.println(ProtocolConstants.SCRIPT_END_MARKER);
97
98             if (partialResponse == PollHandler.PARTIAL_RESPONSE_FLUSH)
99             {
100                 out.print(fourKFlushData);
101             }
102
103             return flush();
104         }
105     }
106
107     /**
108      * Do we need to do the IE 4k flush thing?
109      */

110     protected final int partialResponse;
111 }
112
Popular Tags