001// Copyright 2009, 2010 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007// http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.util;
016
017import java.io.IOException;
018import java.io.OutputStream;
019import java.io.PrintWriter;
020
021import org.apache.tapestry5.http.Link;
022import org.apache.tapestry5.http.services.Response;
023
024/**
025 * Implementation of {@link org.apache.tapestry5.http.services.Response} that delegates all method invocations to a delegate
026 * instance. This is used as a base class for overriding just some behaviors of Response.
027 */
028public class ResponseWrapper implements Response
029{
030    protected final Response response;
031
032    public ResponseWrapper(Response response)
033    {
034        assert response != null;
035        this.response = response;
036    }
037
038    public PrintWriter getPrintWriter(String contentType) throws IOException
039    {
040        return response.getPrintWriter(contentType);
041    }
042
043    public OutputStream getOutputStream(String contentType) throws IOException
044    {
045        return response.getOutputStream(contentType);
046    }
047
048    public void sendRedirect(String URL) throws IOException
049    {
050        response.sendRedirect(URL);
051    }
052
053    public void sendRedirect(Link link) throws IOException
054    {
055        response.sendRedirect(link);
056    }
057
058    public void setStatus(int sc)
059    {
060        response.setStatus(sc);
061    }
062
063    public void sendError(int sc, String message) throws IOException
064    {
065        response.sendError(sc, message);
066    }
067
068    public void setContentLength(int length)
069    {
070        response.setContentLength(length);
071    }
072
073    public void setDateHeader(String name, long date)
074    {
075        response.setDateHeader(name, date);
076    }
077
078    public void setHeader(String name, String value)
079    {
080        response.setHeader(name, value);
081    }
082    
083    public void addHeader(String name, String value)
084    {
085        response.addHeader(name, value);
086    }
087
088    public void setIntHeader(String name, int value)
089    {
090        response.setIntHeader(name, value);
091    }
092
093    public String encodeURL(String URL)
094    {
095        return response.encodeURL(URL);
096    }
097
098    public String encodeRedirectURL(String URL)
099    {
100        return response.encodeRedirectURL(URL);
101    }
102
103    public boolean isCommitted()
104    {
105        return response.isCommitted();
106    }
107
108    public void disableCompression()
109    {
110        response.disableCompression();
111    }
112}