Coverage Report - org.apache.tapestry.web.WebResponse
 
Classes in this File Line Coverage Branch Coverage Complexity
WebResponse
N/A
N/A
1
 
 1  
 // Copyright 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.web;
 16  
 
 17  
 import org.apache.tapestry.util.ContentType;
 18  
 
 19  
 import java.io.IOException;
 20  
 import java.io.OutputStream;
 21  
 import java.io.PrintWriter;
 22  
 
 23  
 /**
 24  
  * Controls the response to the client, and specifically allows for creating the output stream (or
 25  
  * print writer) to which content is sent. This is essentially a generic version of
 26  
  * {@link javax.servlet.http.HttpServletResponse}. Some operations may be unsupported in some
 27  
  * implementations (for example, the portlet implementation can't handle any of the setHeader
 28  
  * methods).
 29  
  * 
 30  
  * @author Howard M. Lewis Ship
 31  
  * @since 4.0
 32  
  */
 33  
 public interface WebResponse
 34  
 {
 35  
     /**
 36  
      * Returns a output stream to which output should be sent. This method should only be invoked
 37  
      * once on a response.
 38  
      *
 39  
      * @param contentType
 40  
      *          The encoding type that this outputstream will write content as.
 41  
      * @return the output stream, configured for the given type.
 42  
      *
 43  
      * @throws IOException On io error.
 44  
      */
 45  
 
 46  
     OutputStream getOutputStream(ContentType contentType)
 47  
       throws IOException;
 48  
 
 49  
     /**
 50  
      * Returns a {@link PrintWriter} to which output should be sent. This method should be invoked
 51  
      * once on a response. A second call is expected to be so that an exception page can be
 52  
      * rendered, and the underlying request data is reset.
 53  
      *
 54  
      * @param contentType
 55  
      *          The type of content encoding the writer is for.
 56  
      * @return A new {@link PrintWriter} instance.
 57  
      *
 58  
      * @throws IOException On io error.
 59  
      */
 60  
 
 61  
     PrintWriter getPrintWriter(ContentType contentType)
 62  
       throws IOException;
 63  
 
 64  
     /**
 65  
      * Encodes a URL, which adds information to the URL needed to ensure that the request triggered
 66  
      * by the URL will be associated with the current session (if any). In most cases, the string is
 67  
      * returned unchanged.
 68  
      *
 69  
      * @param url
 70  
      *          The URL to encode.
 71  
      * @return The url encoded.
 72  
      */
 73  
 
 74  
     String encodeURL(String url);
 75  
 
 76  
     /**
 77  
      * Resets any buffered content. This may be used after an error to radically change what the
 78  
      * output will be.
 79  
      */
 80  
 
 81  
     void reset();
 82  
 
 83  
     /**
 84  
      * Sets the response content length header.
 85  
      *
 86  
      * @param contentLength
 87  
      *          The total content length this response will write. 
 88  
      */
 89  
     void setContentLength(int contentLength);
 90  
 
 91  
     /**
 92  
      * Returns a value to be prefixed or suffixed with any client-side JavaScript elements
 93  
      * (variables and function names) to ensure that they are unique with the context of the entire
 94  
      * page. For servlets, this is the empty string.
 95  
      *
 96  
      * @return The namespace that this requests resources should be pre-pended with.
 97  
      */
 98  
 
 99  
     String getNamespace();
 100  
 
 101  
     /**
 102  
      * Sets a response header as a date.
 103  
      * 
 104  
      * @param name
 105  
      *            the name of the header to set
 106  
      * @param date
 107  
      *            the date value to set, in milliseconds since the epoch
 108  
      */
 109  
     void setDateHeader(String name, long date);
 110  
 
 111  
     /**
 112  
      * Sets a response header as a string.
 113  
      * 
 114  
      * @param name
 115  
      *            the name of the header to set
 116  
      * @param value
 117  
      *            the value for the named header
 118  
      */
 119  
 
 120  
     void setHeader(String name, String value);
 121  
 
 122  
     /**
 123  
      * Sets a response header with the given name and integer value.
 124  
      * 
 125  
      * @param name
 126  
      *            the name of the header to set
 127  
      * @param value
 128  
      *            the value for the named header
 129  
      */
 130  
     void setIntHeader(String name, int value);
 131  
 
 132  
     /**
 133  
      * Sets the status code for this response.
 134  
      *
 135  
      * @param status
 136  
      *          The HTTP status code to set on the return header.
 137  
      */
 138  
     void setStatus(int status);
 139  
 
 140  
     /**
 141  
      * Sends an error response.
 142  
      *
 143  
      * @param statusCode
 144  
      *          The error status code to set on the header.
 145  
      * @param message
 146  
      *          The message to give as the reason for error.
 147  
      *
 148  
      * @throws IOException on io error.
 149  
      */
 150  
     void sendError(int statusCode, String message) throws IOException;
 151  
 }