home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Komunik / sambar / sambar51p.exe / lib / javaeng.jar / javax / servlet / ServletResponse.java < prev    next >
Encoding:
Java Source  |  2001-10-22  |  11.4 KB  |  359 lines

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer. 
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution, if
  20.  *    any, must include the following acknowlegement:  
  21.  *       "This product includes software developed by the 
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowlegement may appear in the software itself,
  24.  *    if and wherever such third-party acknowlegements normally appear.
  25.  *
  26.  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27.  *    Foundation" must not be used to endorse or promote products derived
  28.  *    from this software without prior written permission. For written 
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache"
  32.  *    nor may "Apache" appear in their names without prior written
  33.  *    permission of the Apache Group.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * ====================================================================
  55.  *
  56.  * This source code implements specifications defined by the Java
  57.  * Community Process. In order to remain compliant with the specification
  58.  * DO NOT add / change / or delete method signatures!
  59.  */ 
  60.  
  61. package javax.servlet;
  62.  
  63. import java.io.IOException;
  64. import java.io.PrintWriter;
  65. import java.io.UnsupportedEncodingException;
  66. import java.util.Locale;
  67.  
  68.  
  69. /**
  70.  * Defines an object to assist a servlet in sending a response to the client.
  71.  * The servlet container creates a <code>ServletResponse</code> object and
  72.  * passes it as an argument to the servlet's <code>service</code> method.
  73.  *
  74.  * <p>To send binary data in a MIME body response, use
  75.  * the {@link ServletOutputStream} returned by {@link #getOutputStream}.
  76.  * To send character data, use the <code>PrintWriter</code> object 
  77.  * returned by {@link #getWriter}. To mix binary and text data,
  78.  * for example, to create a multipart response, use a
  79.  * <code>ServletOutputStream</code> and manage the character sections
  80.  * manually.
  81.  *
  82.  * <p>The charset for the MIME body response can be specified with 
  83.  * {@link #setContentType}.  For example, "text/html; charset=Shift_JIS".
  84.  * The charset can alternately be set using {@link #setLocale}.
  85.  * If no charset is specified, ISO-8859-1 will be used.  
  86.  * The <code>setContentType</code> or <code>setLocale</code> method 
  87.  * must be called before <code>getWriter</code> for the charset to 
  88.  * affect the construction of the writer.
  89.  * 
  90.  * <p>See the Internet RFCs such as 
  91.  * <a href="http://info.internet.isi.edu/in-notes/rfc/files/rfc2045.txt">
  92.  * RFC 2045</a> for more information on MIME. Protocols such as SMTP
  93.  * and HTTP define profiles of MIME, and those standards
  94.  * are still evolving.
  95.  *
  96.  * @author     Various
  97.  * @version     $Version$
  98.  *
  99.  * @see        ServletOutputStream
  100.  *
  101.  */
  102.  
  103. public interface ServletResponse {
  104.  
  105.  
  106.     
  107.     /**
  108.      * Returns the name of the charset used for
  109.      * the MIME body sent in this response.
  110.      *
  111.      * <p>If no charset has been assigned, it is implicitly
  112.      * set to <code>ISO-8859-1</code> (<code>Latin-1</code>).
  113.      *
  114.      * <p>See RFC 2047 (http://ds.internic.net/rfc/rfc2045.txt)
  115.      * for more information about character encoding and MIME.
  116.      *
  117.      * @return        a <code>String</code> specifying the
  118.      *            name of the charset, for
  119.      *            example, <code>ISO-8859-1</code>
  120.      *
  121.      */
  122.   
  123.     public String getCharacterEncoding();
  124.     
  125.     
  126.  
  127.     /**
  128.      * Returns a {@link ServletOutputStream} suitable for writing binary 
  129.      * data in the response. The servlet container does not encode the
  130.      * binary data.  Either this method or {@link #getWriter} may 
  131.      * be called to write the body, not both.
  132.      *
  133.      * @return                a {@link ServletOutputStream} for writing binary data    
  134.      *
  135.      * @exception IllegalStateException if the <code>getWriter</code> method
  136.      *                     has been called on this response
  137.      *
  138.      * @exception IOException         if an input or output exception occurred
  139.      *
  140.      * @see                 #getWriter
  141.      *
  142.      */
  143.  
  144.     public ServletOutputStream getOutputStream() throws IOException;
  145.     
  146.     
  147.  
  148.     /**
  149.      * Returns a <code>PrintWriter</code> object that 
  150.      * can send character text to the client. 
  151.      * The character encoding used is the one specified 
  152.      * in the <code>charset=</code> property of the
  153.      * {@link #setContentType} method, which must be called
  154.      * <i>before</i> calling this method for the charset to take effect. 
  155.      *
  156.      * <p>If necessary, the MIME type of the response is 
  157.      * modified to reflect the character encoding used.
  158.      *
  159.      * <p>Either this method or {@link #getOutputStream} may be called
  160.      * to write the body, not both.
  161.      *
  162.      * 
  163.      * @return                 a <code>PrintWriter</code> object that 
  164.      *                    can return character data to the client 
  165.      *
  166.      * @exception UnsupportedEncodingException  if the charset specified in
  167.      *                        <code>setContentType</code> cannot be
  168.      *                        used
  169.      *
  170.      * @exception IllegalStateException        if the <code>getOutputStream</code>
  171.      *                         method has already been called for this 
  172.      *                        response object
  173.      *
  174.      * @exception IOException           if an input or output exception occurred
  175.      *
  176.      * @see                     #getOutputStream
  177.      * @see                     #setContentType
  178.      *
  179.      */
  180.  
  181.     public PrintWriter getWriter() throws IOException;
  182.     
  183.     
  184.     
  185.     
  186.  
  187.     /**
  188.      * Sets the length of the content body in the response
  189.      * In HTTP servlets, this method sets the HTTP Content-Length header.
  190.      *
  191.      *
  192.      * @param len     an integer specifying the length of the 
  193.      *             content being returned to the client; sets
  194.      *            the Content-Length header
  195.      *
  196.      */
  197.  
  198.     public void setContentLength(int len);
  199.     
  200.     
  201.  
  202.     /**
  203.      * Sets the content type of the response being sent to
  204.      * the client. The content type may include the type of character
  205.      * encoding used, for example, <code>text/html; charset=ISO-8859-4</code>.
  206.      *
  207.      * <p>If obtaining a <code>PrintWriter</code>, this method should be 
  208.      * called first.
  209.      *
  210.      *
  211.      * @param type     a <code>String</code> specifying the MIME 
  212.      *            type of the content
  213.      *
  214.      * @see         #getOutputStream
  215.      * @see         #getWriter
  216.      *
  217.      */
  218.  
  219.     public void setContentType(String type);
  220.     
  221.  
  222.     /**
  223.      * Sets the preferred buffer size for the body of the response.  
  224.      * The servlet container will use a buffer at least as large as 
  225.      * the size requested.  The actual buffer size used can be found
  226.      * using <code>getBufferSize</code>.
  227.      *
  228.      * <p>A larger buffer allows more content to be written before anything is
  229.      * actually sent, thus providing the servlet with more time to set
  230.      * appropriate status codes and headers.  A smaller buffer decreases 
  231.      * server memory load and allows the client to start receiving data more
  232.      * quickly.
  233.      *
  234.      * <p>This method must be called before any response body content is
  235.      * written; if content has been written, this method throws an 
  236.      * <code>IllegalStateException</code>.
  237.      *
  238.      * @param size     the preferred buffer size
  239.      *
  240.      * @exception  IllegalStateException      if this method is called after
  241.      *                        content has been written
  242.      *
  243.      * @see         #getBufferSize
  244.      * @see         #flushBuffer
  245.      * @see         #isCommitted
  246.      * @see         #reset
  247.      *
  248.      */
  249.  
  250.     public void setBufferSize(int size);
  251.     
  252.     
  253.  
  254.     /**
  255.      * Returns the actual buffer size used for the response.  If no buffering
  256.      * is used, this method returns 0.
  257.      *
  258.      * @return         the actual buffer size used
  259.      *
  260.      * @see         #setBufferSize
  261.      * @see         #flushBuffer
  262.      * @see         #isCommitted
  263.      * @see         #reset
  264.      *
  265.      */
  266.  
  267.     public int getBufferSize();
  268.     
  269.     
  270.  
  271.     /**
  272.      * Forces any content in the buffer to be written to the client.  A call
  273.      * to this method automatically commits the response, meaning the status 
  274.      * code and headers will be written.
  275.      *
  276.      * @see         #setBufferSize
  277.      * @see         #getBufferSize
  278.      * @see         #isCommitted
  279.      * @see         #reset
  280.      *
  281.      */
  282.  
  283.     public void flushBuffer() throws IOException;
  284.     
  285.     
  286.  
  287.     /**
  288.      * Returns a boolean indicating if the response has been
  289.      * committed.  A commited response has already had its status 
  290.      * code and headers written.
  291.      *
  292.      * @return        a boolean indicating if the response has been
  293.      *          committed
  294.      *
  295.      * @see         #setBufferSize
  296.      * @see         #getBufferSize
  297.      * @see         #flushBuffer
  298.      * @see         #reset
  299.      *
  300.      */
  301.  
  302.     public boolean isCommitted();
  303.     
  304.     
  305.  
  306.     /**
  307.      * Clears any data that exists in the buffer as well as the status code and
  308.      * headers.  If the response has been committed, this method throws an 
  309.      * <code>IllegalStateException</code>.
  310.      *
  311.      * @exception IllegalStateException  if the response has already been
  312.      *                                   committed
  313.      *
  314.      * @see         #setBufferSize
  315.      * @see         #getBufferSize
  316.      * @see         #flushBuffer
  317.      * @see         #isCommitted
  318.      *
  319.      */
  320.  
  321.     public void reset();
  322.     
  323.     
  324.  
  325.     /**
  326.      * Sets the locale of the response, setting the headers (including the
  327.      * Content-Type's charset) as appropriate.  This method should be called
  328.      * before a call to {@link #getWriter}.  By default, the response locale
  329.      * is the default locale for the server.
  330.      * 
  331.      * @param loc  the locale of the response
  332.      *
  333.      * @see         #getLocale
  334.      *
  335.      */
  336.  
  337.     public void setLocale(Locale loc);
  338.     
  339.     
  340.  
  341.     /**
  342.      * Returns the locale assigned to the response.
  343.      * 
  344.      * 
  345.      * @see         #setLocale
  346.      *
  347.      */
  348.  
  349.     public Locale getLocale();
  350.  
  351.  
  352.  
  353. }
  354.  
  355.  
  356.  
  357.  
  358.  
  359.