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    
015    package org.apache.tapestry5.util;
016    
017    import java.io.IOException;
018    import java.io.OutputStream;
019    import java.io.PrintWriter;
020    
021    import org.apache.tapestry5.Link;
022    import org.apache.tapestry5.services.Response;
023    
024    /**
025     * Implementation of {@link org.apache.tapestry5.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     */
028    public 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 setIntHeader(String name, int value)
084        {
085            response.setIntHeader(name, value);
086        }
087    
088        public String encodeURL(String URL)
089        {
090            return response.encodeURL(URL);
091        }
092    
093        public String encodeRedirectURL(String URL)
094        {
095            return response.encodeRedirectURL(URL);
096        }
097    
098        public boolean isCommitted()
099        {
100            return response.isCommitted();
101        }
102    
103        public void disableCompression()
104        {
105            response.disableCompression();
106        }
107    }