KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > httpPresentation > HttpPresentationResponse


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  * $Id: HttpPresentationResponse.java,v 1.1 2005/07/13 11:09:06 slobodan Exp $
23  */

24
25
26
27
28
29 package com.lutris.appserver.server.httpPresentation;
30
31 import javax.servlet.http.Cookie JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33
34 import org.enhydra.xml.io.OutputOptions;
35 import org.enhydra.xml.xmlc.XMLObject;
36 import org.w3c.dom.html.HTMLDocument;
37
38 import com.lutris.appserver.server.session.SessionManager;
39
40 /**
41  * Object passed to presentation objects that is used to generate HTTP
42  * responses.
43  *
44  * @author Mark Diekhans
45  * @version $Revision: 1.1 $
46  */

47 public interface HttpPresentationResponse {
48     /**
49      * Returns the original HttpServletResponse.
50      */

51     public HttpServletResponse JavaDoc getHttpServletResponse();
52
53     /**
54      * Sets the content length for this response.
55      *
56      * @param len the content length
57      */

58     public void setContentLength(int len)
59     throws HttpPresentationException;
60
61     /**
62      * Sets the content type for this response.
63      *
64      * @param type the content's MIME type
65      */

66     public void setContentType(String JavaDoc type)
67     throws HttpPresentationException;
68
69
70     /**
71      * Create an OutputOptions object for a document. Options are default for
72      * the specified document. The object maybe then modified as needed to
73      * override the default values.
74      * <P>
75      * The following attributes are set in the object:
76      * <UL>
77      * <LI> encoding
78      * <LI> MIME type - Defaults for document.
79      * <LI> URLRewriter - Set if URL encoding of sessions is enabled.
80      * </UL>
81      */

82     public OutputOptions createOutputOptions(XMLObject document)
83         throws HttpPresentationException;
84
85     /**
86      * Returns an output stream for writing response data.
87      */

88     public HttpPresentationOutputStream getOutputStream()
89     throws HttpPresentationException;
90
91     /**
92      * Adds the specified cookie to the response. It can be called multiple
93      * times to set more than one cookie.
94      *
95      * @param cookie - The Cookie to return to the client.
96      */

97     public void addCookie(Cookie JavaDoc cookie)
98     throws HttpPresentationException;
99
100     /**
101      * Returns true if the response message header has a field with
102      * the specified name.
103      *
104      * @param name the header field name
105      */

106     public boolean containsHeader(String JavaDoc name)
107     throws HttpPresentationException;
108
109     /**
110      * Sets the status code and message for this response.
111      *
112      * @param sc the status code
113      * @param sm the status message
114      */

115     public void setStatus(int sc, String JavaDoc sm)
116     throws HttpPresentationException;
117
118     /**
119      * Sets the status code and a default message for this response.
120      *
121      * @param sc the status code
122      */

123     public void setStatus(int sc)
124     throws HttpPresentationException;
125
126     /**
127      * Adds a field to the response header with a given name and
128      * value. If the field had already been set, the new value
129      * overwrites the previous one. The containsHeader method can be
130      * used to test for the presence of a header before setting its
131      * value.
132      *
133      * @param name the header field name
134      * @param value the header field value
135      */

136     public void setHeader(String JavaDoc name, String JavaDoc value)
137     throws HttpPresentationException;
138
139     /**
140      * Adds a field to the response header with a given name and
141      * integer value. If the field had already been set, the new
142      * value overwrites the previous one. The containsHeader method
143      * can be used to test for the presence of a header before setting
144      * its value.
145      *
146      * @param name the header field name
147      * @param value the header field integer value
148      */

149     public void setIntHeader(String JavaDoc name, int value)
150     throws HttpPresentationException;
151
152     /**
153      *
154      * Adds a field to the response header with a given name and
155      * date-valued field. The date is specified in terms of
156      * milliseconds since the epoch. If the date field had already
157      * been set, the new value overwrites the previous one. The
158      * containsHeader method can be used to test for the presence of a
159      * header before setting its value.
160      *
161      * @param name the header field name
162      * @param value the header field date value
163      */

164     public void setDateHeader(String JavaDoc name, long date)
165     throws HttpPresentationException;
166
167     /**
168      * Sends an error response to the client using the specified status
169      * code and descriptive message.
170      *
171      * @param sc the status code
172      * @param msg the detail message
173      */

174     public void sendError(int sc, String JavaDoc msg)
175     throws HttpPresentationException;
176
177     /**
178      * Sends an error response to the client using the specified
179      * status code and a default message.
180      *
181      * @param sc the status code
182      */

183     public void sendError(int sc)
184     throws HttpPresentationException;
185
186     //Omitted: sendRedirect(String location)
187

188     //Omitted: public abstract String encodeUrl(String url)
189

190     //Omitted: public abstract String encodeRedirectUrl(String url)
191

192     /**
193      * Called at the end of processing a response to force any cached headers to
194      * be written and buffers flushed. This maybe a no-op if no buffering is
195      * implemented. This is normally not called by a client.
196      */

197     public void flush ()
198     throws HttpPresentationException;
199
200     /**
201      * Output an an XMLC document object (DOM). The document is formatted
202      * according to it's type. The MIME type of the response is automatically
203      * set.
204      *
205      * @param outputFormat Object use to specify options controling formatting
206      * of the document.
207      * @param doc The DOM object to be returned as response.
208      */

209     public void writeDOM(OutputOptions outputOptions,
210                          XMLObject document) throws HttpPresentationException;
211
212     /**
213      * Output an an XMLC document object (DOM). The document is formatted
214      * according to it's type. The MIME type of the response is automatically
215      * set.
216      *
217      * @param doc The DOM object to be returned as response.
218      */

219     public void writeDOM(XMLObject document) throws HttpPresentationException;
220
221     /**
222      * Utility method to output an HTML page. The appropriate headers are
223      * set for MIME type and to disable caching of the HTML by the broswer.
224      */

225     public void writeHTML(String JavaDoc html) throws HttpPresentationException;
226
227     /**
228      * Utility method to output an HTML page from a DOM object. The
229      * appropriate headers are set for MIME type and to disable caching
230      * of the HTML by the broswer.
231      *
232      * @param doc The DOM object to be returned as response
233      * @deprecated use writeDOM
234      * @see #writeDOM
235      */

236     public void writeHTML(HTMLDocument doc) throws HttpPresentationException;
237
238     /**
239      * Set the output character encoding.
240      *
241      * @param enc character encoding
242      */

243     public void setEncoding(String JavaDoc enc);
244
245     /**
246      * Get the output character encoding.
247      *
248      * @return the current encoding
249      */

250     public String JavaDoc getEncoding();
251
252     /**
253      * Sets the current session key for this response
254      *
255      * @param sessionKey
256      * The current sessionKey
257      **/

258     public void setSessionKey(String JavaDoc sessionKey);
259
260     /**
261      * Sets the current application name for this response
262      *
263      * @param appName
264      * The current application name
265      **/

266     public void setSessionManager(SessionManager sessionManager);
267
268     /**
269      * Indicates whether client response requires a sessionId cookie
270      * @return true if client response requires a sessionId cookie
271      * false otherwise
272      */

273     public boolean isSessionIdCookieRequired()
274     throws HttpPresentationException;
275
276     /*
277      * set boolean flag for sessionId response cookie. Indicates whether
278      * client response requires a sessionId cookie
279      * @param isFromCookie boolean flag
280      */

281     public void setSessionIdCookieRequired(boolean sessionIdCookie)
282     throws HttpPresentationException;
283
284     /**
285      * Indicates whether client response requires url encoding for
286      * sessionId
287      * @return true if client response requires url encoding for
288      * sessionId; false otherwise
289      */

290     public boolean isSessionIdEncodeUrlRequired()
291     throws HttpPresentationException;
292
293     /*
294      * set boolean flag url encoding for sessionId. Indicates whether
295      * client response requires url encoding for sessionId
296      * @param sessionIdUrl boolean flag
297      */

298     public void setSessionIdEncodeUrlRequired(boolean sessionIdUrl)
299     throws HttpPresentationException;
300
301     /*
302      * SERVER status codes; see RFC 1945.
303      */

304
305     /**
306      * Status code (200) indicating the request succeeded normally.
307      */

308     public static final int SC_OK = 200;
309
310     /**
311      * Status code (201) indicating the request succeeded and created
312      * a new resource on the server.
313      */

314     public static final int SC_CREATED = 201;
315
316     /**
317      * Status code (202) indicating that a request was accepted for
318      * processing, but was not completed.
319      */

320     public static final int SC_ACCEPTED = 202;
321
322     /**
323      * Status code (204) indicating that the request succeeded but that
324      * there was no new information to return.
325      */

326     public static final int SC_NO_CONTENT = 204;
327
328     /**
329      * Status code (301) indicating that the resource has permanently
330      * moved to a new location, and that future references should use a
331      * new URI with their requests.
332      */

333     public static final int SC_MOVED_PERMANENTLY = 301;
334
335     /**
336      * Status code (302) indicating that the resource has temporarily
337      * moved to another location, but that future references should
338      * still use the original URI to access the resource.
339      */

340     public static final int SC_MOVED_TEMPORARILY = 302;
341
342     /**
343      * Status code (304) indicating that a conditional GET operation
344      * found that the resource was available and not modified.
345      */

346     public static final int SC_NOT_MODIFIED = 304;
347
348     /**
349      * Status code (400) indicating the request sent by the client was
350      * syntactically incorrect.
351      */

352     public static final int SC_BAD_REQUEST = 400;
353
354     /**
355      * Status code (401) indicating that the request requires HTTP
356      * authentication.
357      */

358     public static final int SC_UNAUTHORIZED = 401;
359
360     /**
361      * Status code (403) indicating the server understood the request
362      * but refused to fulfill it.
363      */

364     public static final int SC_FORBIDDEN = 403;
365
366     /**
367      * Status code (404) indicating that the requested resource is not
368      * available.
369      */

370     public static final int SC_NOT_FOUND = 404;
371
372     /**
373      * Status code (500) indicating an error inside the HTTP service
374      * which prevented it from fulfilling the request.
375      */

376     public static final int SC_INTERNAL_SERVER_ERROR = 500;
377
378     /**
379      * Status code (501) indicating the HTTP service does not support
380      * the functionality needed to fulfill the request.
381      */

382     public static final int SC_NOT_IMPLEMENTED = 501;
383
384     /**
385      * Status code (502) indicating that the HTTP server received an
386      * invalid response from a server it consulted when acting as a
387      * proxy or gateway.
388      */

389     public static final int SC_BAD_GATEWAY = 502;
390
391     /**
392      * Status code (503) indicating that the HTTP service is
393      * temporarily overloaded, and unable to handle the request.
394      */

395     public static final int SC_SERVICE_UNAVAILABLE = 503;
396 }
397
Popular Tags