001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: HttpResponse.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.servlet;
009:
010: import com.uwyn.rife.engine.AbstractResponse;
011: import com.uwyn.rife.engine.Request;
012: import com.uwyn.rife.engine.Response;
013: import com.uwyn.rife.engine.exceptions.EngineException;
014: import com.uwyn.rife.servlet.HttpResponse;
015: import java.io.IOException;
016: import java.io.OutputStream;
017: import java.io.PrintWriter;
018: import java.util.Locale;
019: import javax.servlet.http.Cookie;
020: import javax.servlet.http.HttpServletResponse;
021:
022: public class HttpResponse extends AbstractResponse {
023: private HttpServletResponse mResponse = null;
024:
025: public HttpResponse(Request request, HttpServletResponse response,
026: boolean embedded) {
027: super (request, embedded);
028:
029: mResponse = response;
030: }
031:
032: protected void _setContentType(String contentType) {
033: mResponse.setContentType(contentType);
034: }
035:
036: protected String _getCharacterEncoding() {
037: return mResponse.getCharacterEncoding();
038: }
039:
040: protected void _setContentLength(int length) {
041: mResponse.setContentLength(length);
042: }
043:
044: protected void _sendRedirect(String location) {
045: try {
046: mResponse.sendRedirect(location);
047: } catch (IOException e) {
048: throw new EngineException(e);
049: }
050: }
051:
052: protected OutputStream _getOutputStream() throws IOException {
053: return mResponse.getOutputStream();
054: }
055:
056: public Response createEmbeddedResponse(String valueId,
057: String differentiator) {
058: return new HttpResponse(getRequest(), mResponse, true);
059: }
060:
061: public void addCookie(Cookie cookie) {
062: mResponse.addCookie(cookie);
063: }
064:
065: public void addHeader(String name, String value) {
066: mResponse.addHeader(name, value);
067: }
068:
069: public void addDateHeader(String name, long date) {
070: mResponse.addDateHeader(name, date);
071: }
072:
073: public void addIntHeader(String name, int integer) {
074: mResponse.addIntHeader(name, integer);
075: }
076:
077: public boolean containsHeader(String name) {
078: return mResponse.containsHeader(name);
079: }
080:
081: public void sendError(int statusCode) throws EngineException {
082: try {
083: mResponse.sendError(statusCode);
084: } catch (IOException e) {
085: throw new EngineException(e);
086: }
087: }
088:
089: public void sendError(int statusCode, String message)
090: throws EngineException {
091: try {
092: mResponse.sendError(statusCode, message);
093: } catch (IOException e) {
094: throw new EngineException(e);
095: }
096: }
097:
098: public void setDateHeader(String name, long date) {
099: mResponse.setDateHeader(name, date);
100: }
101:
102: public void setHeader(String name, String value) {
103: mResponse.setHeader(name, value);
104: }
105:
106: public void setIntHeader(String name, int value) {
107: mResponse.setIntHeader(name, value);
108: }
109:
110: public void setStatus(int statusCode) {
111: mResponse.setStatus(statusCode);
112: }
113:
114: public String encodeURL(String url) {
115: return mResponse.encodeURL(url);
116: }
117:
118: public void setLocale(Locale locale) {
119: mResponse.setLocale(locale);
120: }
121:
122: public Locale getLocale() {
123: return mResponse.getLocale();
124: }
125:
126: public PrintWriter getWriter() throws IOException {
127: return mResponse.getWriter();
128: }
129:
130: public HttpServletResponse getHttpServletResponse() {
131: return mResponse;
132: }
133: }
|