KickJava   Java API By Example, From Geeks To Geeks.

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


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 HtmlScriptConduit extends BaseScriptConduit
34 {
35     /**
36      * Simple ctor
37      * @param response Used to flush output
38      * @param batchId The id of the batch that we are responding to
39      * @param converterManager How we convert objects to script
40      * @throws IOException If stream ops fail
41      */

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

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

58     public void beginStream()
59     {
60         synchronized (out)
61         {
62             out.println("<html><body>");
63             out.println("<script type=\"text/javascript\">");
64             out.println(EnginePrivate.remoteBeginIFrameResponse(batchId, true));
65             out.println("</script>");
66         }
67     }
68
69     /* (non-Javadoc)
70      * @see org.directwebremoting.dwrp.BaseScriptConduit#endStream()
71      */

72     public void endStream()
73     {
74         synchronized (out)
75         {
76             out.println("<script type=\"text/javascript\">");
77             out.println(EnginePrivate.remoteEndIFrameResponse(batchId, true));
78             out.println("</script>");
79             out.println("</body></html>");
80         }
81     }
82
83     /* (non-Javadoc)
84      * @see org.directwebremoting.ScriptConduit#addScript(org.directwebremoting.ScriptBuffer)
85      */

86     public boolean addScript(ScriptBuffer scriptBuffer) throws IOException JavaDoc, MarshallException
87     {
88         String JavaDoc script = ScriptBufferUtil.createOutput(scriptBuffer, converterManager);
89
90         synchronized (out)
91         {
92             out.println("<script type=\"text/javascript\">");
93             out.println(ProtocolConstants.SCRIPT_START_MARKER);
94             out.println(EnginePrivate.remoteEval(script));
95             out.println(ProtocolConstants.SCRIPT_END_MARKER);
96             out.println("</script>");
97
98             return flush();
99         }
100     }
101 }
102
Popular Tags