KickJava   Java API By Example, From Geeks To Geeks.

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


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.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  * @author Joe Walker [joe at getahead dot ltd dot uk]
31  */

32 public class PlainScriptConduit extends BaseScriptConduit
33 {
34     /**
35      * Simple ctor
36      * @param response Used to flush output
37      * @param batchId The id of the batch that we are responding to
38      * @param converterManager How we convert objects to script
39      * @throws IOException If stream ops fail
40      */

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

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

57     public void beginStream()
58     {
59     }
60
61     /* (non-Javadoc)
62      * @see org.directwebremoting.dwrp.BaseScriptConduit#endStream()
63      */

64     public void endStream()
65     {
66     }
67
68     /* (non-Javadoc)
69      * @see org.directwebremoting.ScriptConduit#addScript(org.directwebremoting.ScriptBuffer)
70      */

71     public boolean addScript(ScriptBuffer scriptBuffer) throws IOException JavaDoc, MarshallException
72     {
73         String JavaDoc script = ScriptBufferUtil.createOutput(scriptBuffer, converterManager);
74
75         synchronized (out)
76         {
77             out.println(ProtocolConstants.SCRIPT_START_MARKER);
78             out.println(script);
79             out.println(ProtocolConstants.SCRIPT_END_MARKER);
80
81             return flush();
82         }
83     }
84 }
85
Popular Tags