KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > go > teaservlet > ApplicationResponse


1 /* ====================================================================
2  * TeaServlet - Copyright (c) 1999-2000 Walt Disney Internet Group
3  * ====================================================================
4  * The Tea Software License, Version 1.1
5  *
6  * Copyright (c) 2000 Walt Disney Internet Group. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Walt Disney Internet Group (http://opensource.go.com/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Tea", "TeaServlet", "Kettle", "Trove" and "BeanDoc" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact opensource@dig.com.
31  *
32  * 5. Products derived from this software may not be called "Tea",
33  * "TeaServlet", "Kettle" or "Trove", nor may "Tea", "TeaServlet",
34  * "Kettle", "Trove" or "BeanDoc" appear in their name, without prior
35  * written permission of the Walt Disney Internet Group.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE WALT DISNEY INTERNET GROUP OR ITS
41  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
42  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
43  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
44  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
45  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48  * ====================================================================
49  *
50  * For more information about Tea, please see http://opensource.go.com/.
51  */

52
53 package com.go.teaservlet;
54
55 import java.io.Serializable JavaDoc;
56 import javax.servlet.http.*;
57 import com.go.teaservlet.io.CharToByteBuffer;
58 import com.go.tea.runtime.OutputReceiver;
59 import com.go.tea.runtime.Substitution;
60
61 /******************************************************************************
62  * An ordinary HttpServletResponse, but with additional operations specific
63  * to the TeaServlet.
64  *
65  * @author Brian S O'Neill
66  * @version
67  * <!--$$Revision:--> 21 <!-- $-->, <!--$$JustDate:--> 01/07/12 <!-- $-->
68  */

69 public interface ApplicationResponse extends HttpServletResponse {
70     /**
71      * Returns whether a redirect or error will be sent to the client. This
72      * is set to true when sendError or sendRedirect is called on the response.
73      */

74     public boolean isRedirectOrError();
75
76     /**
77      * Returns the internal buffer that stores the response. Applications can
78      * use this to directly supply character or byte data to be output.
79      */

80     public CharToByteBuffer getResponseBuffer();
81
82     /**
83      * Provides direct access to the HttpContext that the template has access
84      * to. This allows functions to directly control locale and formatting
85      * settings as well as perform string conversion against the current
86      * format settings.
87      * <p>
88      * The returned HttpContext instance is actually an auto-generated class
89      * that merges all the application contexts into one. Application context
90      * instances are requested only when the merged context first needs to
91      * invoke a function from that context.
92      * <p>
93      * Application functions can access functions provided by other
94      * applications, possibly using the Java reflection APIs. Also, the merged
95      * class implements as many context interfaces as possible. Therefore,
96      * casting the context to an expected type can also be used to access other
97      * application functions.
98      */

99     public HttpContext getHttpContext();
100
101     /**
102      * Execute the given template substitution, but steal any output that would
103      * have gone directly to the response buffer. Applications can use this
104      * to specially handle the output of special objects. For example, an
105      * application can supply functions that allow templates to create
106      * downloadable images. By stealing the output, printed text can go to the
107      * image instead of corrupting the encoding.
108      * <p>
109      * Note: stealOutput is designed to run in the same thread that executed
110      * the main template. If the substitution needs to run in a separate
111      * thread, consider {@link #execDetached} instead.
112      *
113      * @param s template substitution block that will be executed
114      * @param receiver receives all the output generated by the substitution
115      * @throws any exception thrown by the substitution or receiver
116      */

117     public void stealOutput(Substitution s, OutputReceiver receiver)
118         throws Exception JavaDoc;
119
120     /**
121      * Execute the given template substitution and detach everything sent to
122      * the ApplicationResponse in a way that's safe to do asynchronously.
123      * This is useful for certain caching strategies. The substitution is
124      * detached and executed with a new context instance and output buffer.
125      *
126      * @param s template substitution block that will be executed
127      * @return the detached response data, which is essentially a copy
128      * @throws any exception thrown by the substitution or buffer
129      */

130     public DetachedData execDetached(Substitution s) throws Exception JavaDoc;
131
132     /**
133      * Execute the given command and detach everything sent to the
134      * ApplicationResponse in a way that's safe to do asynchronously.
135      * This is useful for certain caching strategies. The ApplicationResponse
136      * given to the command contains a new context instance and output buffer.
137      *
138      * @param s template substitution block that will be executed
139      * @return the detached response data, which is essentially a copy
140      * @throws any exception thrown by the command or buffer
141      */

142     public DetachedData execDetached(Command command) throws Exception JavaDoc;
143
144     /**
145      * Insert an arbitrary command into this response. If this response is
146      * saving its state in a DetachedData instance, then the command
147      * will be executed every time the DetachedData is played back.
148      * If this response isn't detached, the command is not executed and false
149      * is returned.
150      *
151      * @return false if command cannot be inserted because no detached
152      * execution is in progress.
153      */

154     public boolean insertCommand(Command command) throws Exception JavaDoc;
155
156     /**
157      * Commits this response and fully writes out the buffered contents unless
158      * there was a redirect or an error. Subsequent calls to finish have no
159      * affect.
160      *
161      * @throws IllegalArgumentException if a Writer was already used for
162      * writing to the response.
163      */

164     public void finish() throws java.io.IOException JavaDoc;
165
166     public interface DetachedData extends Serializable JavaDoc {
167         public void playback(ApplicationRequest request,
168                              ApplicationResponse response) throws Exception JavaDoc;
169         
170         /**
171          * Compresses all the byte buffers using a deflater, unless already
172          * called before. When this DetachedData is later played back for a
173          * request that accepts a compressed encoding, the compressed data is
174          * output. If the request doesn't accept compression, the original
175          * uncompressed data is output.
176          * <p>
177          * The deflater will usually use default strategy, default compression.
178          * If the amount of data to compress is small, the "no compression" (0)
179          * level is used.
180          */

181         public void compress();
182
183         /**
184          * Compresses all the byte buffers using a deflater, unless already
185          * called before. When this DetachedData is later played back for a
186          * request that accepts a compressed encoding, the compressed data is
187          * output. If the request doesn't accept compression, the original
188          * uncompressed data is output.
189          * <p>
190          * If the amount of data to compress is small, the "no compression" (0)
191          * level is used.
192          *
193          * @param level compression level 1 to 9. 1 is fastest, 9 offers best
194          * compression. 6 is default.
195          */

196         public void compress(int level);
197     }
198
199     public interface Command {
200         public void execute(ApplicationRequest request,
201                             ApplicationResponse response) throws Exception JavaDoc;
202     }
203 }
204
Popular Tags