org.mmbase.util
Class GenericResponseWrapper

java.lang.Object
  extended byjavax.servlet.ServletResponseWrapper
      extended byjavax.servlet.http.HttpServletResponseWrapper
          extended byorg.mmbase.util.GenericResponseWrapper
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class GenericResponseWrapper
extends javax.servlet.http.HttpServletResponseWrapper

Wrapper around the response. It collects all data that is sent to it, and makes it available through a toString() method. It is used by taglib's Include-Tag, but it might find more general use, outside taglib.

Since:
MMBase-1.7
Version:
$Id: GenericResponseWrapper.java,v 1.3.2.7 2004/09/22 07:25:25 keesj Exp $
Author:
Kees Jongenburger, Johannes Verelst, Michiel Meeuwissen

Field Summary
static java.lang.String TEXT_XML_DEFAULT_CHARSET
           
 
Fields inherited from interface javax.servlet.http.HttpServletResponse
SC_ACCEPTED, SC_BAD_GATEWAY, SC_BAD_REQUEST, SC_CONFLICT, SC_CONTINUE, SC_CREATED, SC_EXPECTATION_FAILED, SC_FORBIDDEN, SC_GATEWAY_TIMEOUT, SC_GONE, SC_HTTP_VERSION_NOT_SUPPORTED, SC_INTERNAL_SERVER_ERROR, SC_LENGTH_REQUIRED, SC_METHOD_NOT_ALLOWED, SC_MOVED_PERMANENTLY, SC_MOVED_TEMPORARILY, SC_MULTIPLE_CHOICES, SC_NO_CONTENT, SC_NON_AUTHORITATIVE_INFORMATION, SC_NOT_ACCEPTABLE, SC_NOT_FOUND, SC_NOT_IMPLEMENTED, SC_NOT_MODIFIED, SC_OK, SC_PARTIAL_CONTENT, SC_PAYMENT_REQUIRED, SC_PRECONDITION_FAILED, SC_PROXY_AUTHENTICATION_REQUIRED, SC_REQUEST_ENTITY_TOO_LARGE, SC_REQUEST_TIMEOUT, SC_REQUEST_URI_TOO_LONG, SC_REQUESTED_RANGE_NOT_SATISFIABLE, SC_RESET_CONTENT, SC_SEE_OTHER, SC_SERVICE_UNAVAILABLE, SC_SWITCHING_PROTOCOLS, SC_TEMPORARY_REDIRECT, SC_UNAUTHORIZED, SC_UNSUPPORTED_MEDIA_TYPE, SC_USE_PROXY
 
Constructor Summary
GenericResponseWrapper(javax.servlet.http.HttpServletResponse resp)
          Public constructor
GenericResponseWrapper(javax.servlet.http.HttpServletResponse resp, java.lang.String encoding)
          Sets also a value for the characterEncoding which must be supposed.
 
Method Summary
 void addCookie(javax.servlet.http.Cookie c)
           
protected  byte[] determinXMLEncoding()
           
 java.lang.String getCharacterEncoding()
          Returns the name of the charset used for the MIME body sent in this response.
static java.lang.String getDefaultEncoding(java.lang.String contentType)
          Supposes that no explicit charset is mentioned in a contentType, and returns a default.
static java.lang.String getEncoding(java.lang.String contentType)
          Takes the value of a Content-Type header, and tries to find the encoding from it.
 javax.servlet.http.HttpServletResponse getHttpServletResponse()
          Gets the response object which this wrapper is wrapping.
 javax.servlet.ServletOutputStream getOutputStream()
          Return the OutputStream.
 java.io.PrintWriter getWriter()
          Return the PrintWriter
static java.lang.String getXMLEncoding(byte[] allBytes)
          Takes a ByteArrayInputStream, which is considered to be (the first) part of an XML, and returns the encoding.
static java.lang.String getXMLEncoding(java.lang.String xmlString)
          Takes a String, which is considered to be (the first) part of an XML, and returns the encoding (the specified one, or the XML default)
 void sendRedirect(java.lang.String location)
           
 void setContentType(java.lang.String ct)
          Sets the content type of the response being sent to the client.
 void setHeader(java.lang.String header, java.lang.String value)
           
 void setStatus(int s)
           
 java.lang.String toString()
          Return all data that has been written to the PrintWriter.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
addDateHeader, addHeader, addIntHeader, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendError, sendError, setDateHeader, setIntHeader, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
flushBuffer, getBufferSize, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setContentLength, setLocale, setResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletResponse
flushBuffer, getBufferSize, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setContentLength, setLocale
 

Field Detail

TEXT_XML_DEFAULT_CHARSET

public static java.lang.String TEXT_XML_DEFAULT_CHARSET
Constructor Detail

GenericResponseWrapper

public GenericResponseWrapper(javax.servlet.http.HttpServletResponse resp)
Public constructor


GenericResponseWrapper

public GenericResponseWrapper(javax.servlet.http.HttpServletResponse resp,
                              java.lang.String encoding)
Sets also a value for the characterEncoding which must be supposed. Normally it would be determined automaticly right, but if for some reason it doesn't you can override it.

Method Detail

getXMLEncoding

public static final java.lang.String getXMLEncoding(java.lang.String xmlString)
Takes a String, which is considered to be (the first) part of an XML, and returns the encoding (the specified one, or the XML default)

Since:
MMBase-1.7.1
See Also:
getXMLEncoding(byte[])

getXMLEncoding

public static java.lang.String getXMLEncoding(byte[] allBytes)
Takes a ByteArrayInputStream, which is considered to be (the first) part of an XML, and returns the encoding.

Since:
MMBase-1.7.1
See Also:
getXMLEncoding(String)

getEncoding

public static java.lang.String getEncoding(java.lang.String contentType)
Takes the value of a Content-Type header, and tries to find the encoding from it.

Returns:
The found charset if found, otherwise 'null'
Since:
MMBase-1.7.1

getDefaultEncoding

public static java.lang.String getDefaultEncoding(java.lang.String contentType)
Supposes that no explicit charset is mentioned in a contentType, and returns a default. (UTF-8 or US-ASCII for XML types and ISO-8859-1 otherwise).

Returns:
A charset.
Since:
MMBase-1.7.1

getHttpServletResponse

public javax.servlet.http.HttpServletResponse getHttpServletResponse()
Gets the response object which this wrapper is wrapping. You might need this when giving a redirect or so.

Since:
MMBase-1.7.1

sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Throws:
java.io.IOException

setStatus

public void setStatus(int s)

addCookie

public void addCookie(javax.servlet.http.Cookie c)

setHeader

public void setHeader(java.lang.String header,
                      java.lang.String value)

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Return the OutputStream. This is a 'MyServletOutputStream'.

Throws:
java.io.IOException

getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Return the PrintWriter

Throws:
java.io.IOException

setContentType

public void setContentType(java.lang.String ct)
Sets the content type of the response being sent to the client. The content type may include the type of character encoding used, for example, text/html; charset=ISO-8859-4. If obtaining a PrintWriter, this method should be called first.


getCharacterEncoding

public java.lang.String getCharacterEncoding()
Returns the name of the charset used for the MIME body sent in this response. If no charset has been assigned, it is implicitly set to ISO-8859-1 (Latin-1). See RFC 2047 for more information about character encoding and MIME. returns the encoding


determinXMLEncoding

protected byte[] determinXMLEncoding()

toString

public java.lang.String toString()
Return all data that has been written to the PrintWriter.



MMBase build 1.7.1.20041002