01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
18:
19: import java.io.IOException;
20: import java.io.OutputStream;
21: import java.io.PrintWriter;
22:
23: import javax.servlet.http.HttpServletResponse;
24:
25: import org.apache.tapestry.ioc.internal.util.Defense;
26: import org.apache.tapestry.services.Response;
27:
28: /**
29: * Implementation of {@link Response} that wraps around an underlying {@link HttpServletResponse}.
30: */
31: public class ResponseImpl implements Response {
32: private final HttpServletResponse _response;
33:
34: public ResponseImpl(HttpServletResponse response) {
35: Defense.notNull(response, "response");
36:
37: _response = response;
38: }
39:
40: public PrintWriter getPrintWriter(String contentType)
41: throws IOException {
42: notBlank(contentType, "contentType");
43:
44: _response.setContentType(contentType);
45:
46: return _response.getWriter();
47: }
48:
49: public String encodeURL(String URL) {
50: return _response.encodeURL(URL);
51: }
52:
53: public String encodeRedirectURL(String URL) {
54: return _response.encodeRedirectURL(URL);
55: }
56:
57: public void sendRedirect(String URL) throws IOException {
58: _response.sendRedirect(URL);
59: }
60:
61: public OutputStream getOutputStream(String contentType)
62: throws IOException {
63: notBlank(contentType, "contentType");
64:
65: _response.setContentType(contentType);
66:
67: return _response.getOutputStream();
68: }
69:
70: public void sendError(int sc, String message) throws IOException {
71: _response.sendError(sc, message);
72: }
73:
74: public void setContentLength(int length) {
75: _response.setContentLength(length);
76: }
77:
78: public void setDateHeader(String name, long date) {
79: _response.setDateHeader(name, date);
80: }
81:
82: public void setHeader(String name, String value) {
83: _response.setHeader(name, value);
84: }
85:
86: public void setIntHeader(String name, int value) {
87: _response.setIntHeader(name, value);
88: }
89:
90: }
|