Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » coyote » tomcat4 » [javadoc | source]
    1   /*
    2    *  Copyright 1999-2004 The Apache Software Foundation
    3    *
    4    *  Licensed under the Apache License, Version 2.0 (the "License");
    5    *  you may not use this file except in compliance with the License.
    6    *  You may obtain a copy of the License at
    7    *
    8    *      http://www.apache.org/licenses/LICENSE-2.0
    9    *
   10    *  Unless required by applicable law or agreed to in writing, software
   11    *  distributed under the License is distributed on an "AS IS" BASIS,
   12    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13    *  See the License for the specific language governing permissions and
   14    *  limitations under the License.
   15    */
   16   
   17   package org.apache.coyote.tomcat4;
   18   
   19   
   20   import java.io.IOException;
   21   import java.io.PrintWriter;
   22   import java.util.Locale;
   23   
   24   import javax.servlet.ServletOutputStream;
   25   import javax.servlet.http.Cookie;
   26   import javax.servlet.http.HttpServletResponse;
   27   
   28   import org.apache.catalina.connector.ResponseFacade;
   29   
   30   /**
   31    * Facade class that wraps a Coyote response object. 
   32    * All methods are delegated to the wrapped response.
   33    *
   34    * @author Remy Maucherat
   35    * @version $Revision: 299222 $ $Date: 2004-02-24 04:02:18 -0500 (Tue, 24 Feb 2004) $
   36    */
   37   
   38   public class CoyoteResponseFacade 
   39       extends ResponseFacade
   40       implements HttpServletResponse {
   41   
   42   
   43       // ----------------------------------------------------------- Constructors
   44   
   45   
   46       /**
   47        * Construct a wrapper for the specified response.
   48        *
   49        * @param response The response to be wrapped
   50        */
   51       public CoyoteResponseFacade(CoyoteResponse response) {
   52   
   53           super(response);
   54           this.response = response;
   55   
   56       }
   57   
   58   
   59       // ----------------------------------------------------- Instance Variables
   60   
   61   
   62       /**
   63        * The wrapped response.
   64        */
   65       protected CoyoteResponse response = null;
   66   
   67   
   68       // --------------------------------------------------------- Public Methods
   69   
   70   
   71       /**
   72        * Clear facade.
   73        */
   74       public void clear() {
   75           response = null;
   76       }
   77   
   78   
   79       public void finish() {
   80   
   81           response.setSuspended(true);
   82   
   83       }
   84   
   85   
   86       public boolean isFinished() {
   87   
   88           return response.isSuspended();
   89   
   90       }
   91   
   92   
   93       // ------------------------------------------------ ServletResponse Methods
   94   
   95   
   96       public String getCharacterEncoding() {
   97           return response.getCharacterEncoding();
   98       }
   99   
  100   
  101       public ServletOutputStream getOutputStream()
  102           throws IOException {
  103   
  104           //        if (isFinished())
  105           //            throw new IllegalStateException
  106           //                (/*sm.getString("responseFacade.finished")*/);
  107   
  108           ServletOutputStream sos = response.getOutputStream();
  109           if (isFinished())
  110               response.setSuspended(true);
  111           return (sos);
  112   
  113       }
  114   
  115   
  116       public PrintWriter getWriter()
  117           throws IOException {
  118   
  119           //        if (isFinished())
  120           //            throw new IllegalStateException
  121           //                (/*sm.getString("responseFacade.finished")*/);
  122   
  123           PrintWriter writer = response.getWriter();
  124           if (isFinished())
  125               response.setSuspended(true);
  126           return (writer);
  127   
  128       }
  129   
  130   
  131       public void setContentLength(int len) {
  132   
  133           if (isCommitted())
  134               return;
  135   
  136           response.setContentLength(len);
  137   
  138       }
  139   
  140   
  141       public void setContentType(String type) {
  142   
  143           if (isCommitted())
  144               return;
  145   
  146           response.setContentType(type);
  147   
  148       }
  149   
  150   
  151       public void setBufferSize(int size) {
  152   
  153           if (isCommitted())
  154               throw new IllegalStateException
  155                   (/*sm.getString("responseBase.reset.ise")*/);
  156   
  157           response.setBufferSize(size);
  158   
  159       }
  160   
  161   
  162       public int getBufferSize() {
  163           return response.getBufferSize();
  164       }
  165   
  166   
  167       public void flushBuffer()
  168           throws IOException {
  169   
  170           if (isFinished())
  171               //            throw new IllegalStateException
  172               //                (/*sm.getString("responseFacade.finished")*/);
  173               return;
  174   
  175           response.setAppCommitted(true);
  176   
  177           response.flushBuffer();
  178   
  179       }
  180   
  181   
  182       public void resetBuffer() {
  183   
  184           if (isCommitted())
  185               throw new IllegalStateException
  186                   (/*sm.getString("responseBase.reset.ise")*/);
  187   
  188           response.resetBuffer();
  189   
  190       }
  191   
  192   
  193       public boolean isCommitted() {
  194           return (response.isAppCommitted());
  195       }
  196   
  197   
  198       public void reset() {
  199   
  200           if (isCommitted())
  201               throw new IllegalStateException
  202                   (/*sm.getString("responseBase.reset.ise")*/);
  203   
  204           response.reset();
  205   
  206       }
  207   
  208   
  209       public void setLocale(Locale loc) {
  210   
  211           if (isCommitted())
  212               return;
  213   
  214           response.setLocale(loc);
  215       }
  216   
  217   
  218       public Locale getLocale() {
  219           return response.getLocale();
  220       }
  221   
  222   
  223       public void addCookie(Cookie cookie) {
  224   
  225           if (isCommitted())
  226               return;
  227   
  228           response.addCookie(cookie);
  229   
  230       }
  231   
  232   
  233       public boolean containsHeader(String name) {
  234           return response.containsHeader(name);
  235       }
  236   
  237   
  238       public String encodeURL(String url) {
  239           return response.encodeURL(url);
  240       }
  241   
  242   
  243       public String encodeRedirectURL(String url) {
  244           return response.encodeRedirectURL(url);
  245       }
  246   
  247   
  248       public String encodeUrl(String url) {
  249           return response.encodeURL(url);
  250       }
  251   
  252   
  253       public String encodeRedirectUrl(String url) {
  254           return response.encodeRedirectURL(url);
  255       }
  256   
  257   
  258       public void sendError(int sc, String msg)
  259           throws IOException {
  260   
  261           if (isCommitted())
  262               throw new IllegalStateException
  263                   (/*sm.getString("responseBase.reset.ise")*/);
  264   
  265           response.setAppCommitted(true);
  266   
  267           response.sendError(sc, msg);
  268   
  269       }
  270   
  271   
  272       public void sendError(int sc)
  273           throws IOException {
  274   
  275           if (isCommitted())
  276               throw new IllegalStateException
  277                   (/*sm.getString("responseBase.reset.ise")*/);
  278   
  279           response.setAppCommitted(true);
  280   
  281           response.sendError(sc);
  282   
  283       }
  284   
  285   
  286       public void sendRedirect(String location)
  287           throws IOException {
  288   
  289           if (isCommitted())
  290               throw new IllegalStateException
  291                   (/*sm.getString("responseBase.reset.ise")*/);
  292   
  293           response.setAppCommitted(true);
  294   
  295           response.sendRedirect(location);
  296   
  297       }
  298   
  299   
  300       public void setDateHeader(String name, long date) {
  301   
  302           if (isCommitted())
  303               return;
  304   
  305           response.setDateHeader(name, date);
  306   
  307       }
  308   
  309   
  310       public void addDateHeader(String name, long date) {
  311   
  312           if (isCommitted())
  313               return;
  314   
  315           response.addDateHeader(name, date);
  316   
  317       }
  318   
  319   
  320       public void setHeader(String name, String value) {
  321   
  322           if (isCommitted())
  323               return;
  324   
  325           response.setHeader(name, value);
  326   
  327       }
  328   
  329   
  330       public void addHeader(String name, String value) {
  331   
  332           if (isCommitted())
  333               return;
  334   
  335           response.addHeader(name, value);
  336   
  337       }
  338   
  339   
  340       public void setIntHeader(String name, int value) {
  341   
  342           if (isCommitted())
  343               return;
  344   
  345           response.setIntHeader(name, value);
  346   
  347       }
  348   
  349   
  350       public void addIntHeader(String name, int value) {
  351   
  352           if (isCommitted())
  353               return;
  354   
  355           response.addIntHeader(name, value);
  356   
  357       }
  358   
  359   
  360       public void setStatus(int sc) {
  361   
  362           if (isCommitted())
  363               return;
  364   
  365           response.setStatus(sc);
  366   
  367       }
  368   
  369   
  370       public void setStatus(int sc, String sm) {
  371   
  372           if (isCommitted())
  373               return;
  374   
  375           response.setStatus(sc, sm);
  376   
  377       }
  378   
  379   
  380   }

Save This Page
Home » apache-tomcat-6.0.16-src » org.apache » coyote » tomcat4 » [javadoc | source]