FileDocCategorySizeDatePackage
ResponseFacade.javaAPI DocApache Tomcat 6.0.1413386Fri Jul 20 04:20:32 BST 2007org.apache.catalina.connector

ResponseFacade

public class ResponseFacade extends Object implements HttpServletResponse
Facade class that wraps a Coyote response object. All methods are delegated to the wrapped response.
author
Remy Maucherat
author
Jean-Francois Arcand
version
$Revision: 505593 $ $Date: 2007-02-10 01:54:56 +0100 (sam., 10 févr. 2007) $

Fields Summary
protected static org.apache.catalina.util.StringManager
sm
The string manager for this package.
protected Response
response
The wrapped response.
Constructors Summary
public ResponseFacade(Response response)
Construct a wrapper for the specified response.

param
response The response to be wrapped


         this.response = response;
    
Methods Summary
public voidaddCookie(javax.servlet.http.Cookie cookie)


        if (isCommitted())
            return;

        response.addCookie(cookie);

    
public voidaddDateHeader(java.lang.String name, long date)


        if (isCommitted())
            return;

        if(Globals.IS_SECURITY_ENABLED) {
            AccessController.doPrivileged(new DateHeaderPrivilegedAction
                                             (name, date, true));
        } else {
            response.addDateHeader(name, date);
        }

    
public voidaddHeader(java.lang.String name, java.lang.String value)


        if (isCommitted())
            return;

        response.addHeader(name, value);

    
public voidaddIntHeader(java.lang.String name, int value)


        if (isCommitted())
            return;

        response.addIntHeader(name, value);

    
public voidclear()
Clear facade.



    // --------------------------------------------------------- Public Methods


           
       
        response = null;
    
protected java.lang.Objectclone()
Prevent cloning the facade.

        throw new CloneNotSupportedException();
    
public booleancontainsHeader(java.lang.String name)


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.containsHeader(name);
    
public java.lang.StringencodeRedirectURL(java.lang.String url)


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.encodeRedirectURL(url);
    
public java.lang.StringencodeRedirectUrl(java.lang.String url)


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.encodeRedirectURL(url);
    
public java.lang.StringencodeURL(java.lang.String url)


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.encodeURL(url);
    
public java.lang.StringencodeUrl(java.lang.String url)


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.encodeURL(url);
    
public voidfinish()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        response.setSuspended(true);
    
public voidflushBuffer()


        if (isFinished())
            //            throw new IllegalStateException
            //                (/*sm.getString("responseFacade.finished")*/);
            return;

        if (SecurityUtil.isPackageProtectionEnabled()){
            try{
                AccessController.doPrivileged(new PrivilegedExceptionAction(){

                    public Object run() throws IOException{
                        response.setAppCommitted(true);

                        response.flushBuffer();
                        return null;
                    }
                });
            } catch(PrivilegedActionException e){
                Exception ex = e.getException();
                if (ex instanceof IOException){
                    throw (IOException)ex;
                }
            }
        } else {
            response.setAppCommitted(true);

            response.flushBuffer();            
        }

    
public intgetBufferSize()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.getBufferSize();
    
public java.lang.StringgetCharacterEncoding()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.getCharacterEncoding();
    
public java.lang.StringgetContentType()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.getContentType();
    
public java.util.LocalegetLocale()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.getLocale();
    
public javax.servlet.ServletOutputStreamgetOutputStream()


        //        if (isFinished())
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);

        ServletOutputStream sos = response.getOutputStream();
        if (isFinished())
            response.setSuspended(true);
        return (sos);

    
public java.io.PrintWritergetWriter()


        //        if (isFinished())
        //            throw new IllegalStateException
        //                (/*sm.getString("responseFacade.finished")*/);

        PrintWriter writer = response.getWriter();
        if (isFinished())
            response.setSuspended(true);
        return (writer);

    
public booleanisCommitted()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return (response.isAppCommitted());
    
public booleanisFinished()


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        return response.isSuspended();
    
public voidreset()


        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.reset();

    
public voidresetBuffer()


        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.resetBuffer();

    
public voidsendError(int sc, java.lang.String msg)


        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.setAppCommitted(true);

        response.sendError(sc, msg);

    
public voidsendError(int sc)


        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.setAppCommitted(true);

        response.sendError(sc);

    
public voidsendRedirect(java.lang.String location)


        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.setAppCommitted(true);

        response.sendRedirect(location);

    
public voidsetBufferSize(int size)


        if (isCommitted())
            throw new IllegalStateException
                (/*sm.getString("responseBase.reset.ise")*/);

        response.setBufferSize(size);

    
public voidsetCharacterEncoding(java.lang.String arg0)


        if (response == null) {
            throw new IllegalStateException(
                            sm.getString("responseFacade.nullResponse"));
        }

        response.setCharacterEncoding(arg0);
    
public voidsetContentLength(int len)


        if (isCommitted())
            return;

        response.setContentLength(len);

    
public voidsetContentType(java.lang.String type)


        if (isCommitted())
            return;
        
        if (SecurityUtil.isPackageProtectionEnabled()){
            AccessController.doPrivileged(new SetContentTypePrivilegedAction(type));
        } else {
            response.setContentType(type);            
        }
    
public voidsetDateHeader(java.lang.String name, long date)


        if (isCommitted())
            return;

        if(Globals.IS_SECURITY_ENABLED) {
            AccessController.doPrivileged(new DateHeaderPrivilegedAction
                                             (name, date, false));
        } else {
            response.setDateHeader(name, date);
        }

    
public voidsetHeader(java.lang.String name, java.lang.String value)


        if (isCommitted())
            return;

        response.setHeader(name, value);

    
public voidsetIntHeader(java.lang.String name, int value)


        if (isCommitted())
            return;

        response.setIntHeader(name, value);

    
public voidsetLocale(java.util.Locale loc)


        if (isCommitted())
            return;

        response.setLocale(loc);
    
public voidsetStatus(int sc)


        if (isCommitted())
            return;

        response.setStatus(sc);

    
public voidsetStatus(int sc, java.lang.String sm)


        if (isCommitted())
            return;

        response.setStatus(sc, sm);