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:
HttpServletResponse, ServletResponse

public class GenericResponseWrapper
extends 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.17 2006/03/24 16:51:27 nklasens Exp $
Author:
Kees Jongenburger, Johannes Verelst, Michiel Meeuwissen

Field Summary
static 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(HttpServletResponse resp)
          Public constructor
GenericResponseWrapper(HttpServletResponse resp, String encoding)
          Sets also a value for the characterEncoding which must be supposed.
 
Method Summary
 void addCookie(Cookie c)
           
 void addDateHeader(String arg0, long arg1)
           
 void addHeader(String arg0, String arg1)
           
 void addIntHeader(String arg0, int arg1)
           
 boolean containsHeader(String arg0)
           
protected  byte[] determinXMLEncoding()
           
 String encodeRedirectURL(String arg0)
           
 String encodeURL(String arg0)
           
 String getCharacterEncoding()
          Returns the name of the charset used for the MIME body sent in this response.
static String getDefaultEncoding(String contentType)
          Supposes that no explicit charset is mentioned in a contentType, and returns a default.
static String getEncoding(String contentType)
          Takes the value of a Content-Type header, and tries to find the encoding from it.
 HttpServletResponse getHttpServletResponse()
          Gets the response object which this wrapper is wrapping.
 Locale getLocale()
           
 ServletOutputStream getOutputStream()
          Return the OutputStream.
 PrintWriter getWriter()
          Return the PrintWriter
static String getXMLEncoding(byte[] allBytes)
          Takes a ByteArrayInputStream, which is considered to be (the first) part of an XML, and returns the encoding.
static String getXMLEncoding(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 sendError(int arg0)
           
 void sendError(int arg0, String arg1)
           
 void sendRedirect(String location)
           
 void setContentType(String ct)
          Sets the content type of the response being sent to the client.
 void setDateHeader(String arg0, long arg1)
           
 void setHeader(String header, String value)
           
 void setIntHeader(String arg0, int arg1)
           
 void setLocale(Locale arg0)
           
 void setStatus(int s)
           
 String toString()
          Return all data that has been written to the PrintWriter.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
encodeRedirectUrl, encodeUrl, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
flushBuffer, getBufferSize, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setContentLength, 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, isCommitted, reset, resetBuffer, setBufferSize, setContentLength
 

Field Detail

TEXT_XML_DEFAULT_CHARSET

public static String TEXT_XML_DEFAULT_CHARSET
Constructor Detail

GenericResponseWrapper

public GenericResponseWrapper(HttpServletResponse resp)
Public constructor


GenericResponseWrapper

public GenericResponseWrapper(HttpServletResponse resp,
                              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

getHttpServletResponse

public 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(String location)
                  throws IOException
Throws:
IOException

setStatus

public void setStatus(int s)

addCookie

public void addCookie(Cookie c)

setHeader

public void setHeader(String header,
                      String value)

addDateHeader

public void addDateHeader(String arg0,
                          long arg1)
See Also:
HttpServletResponse.addDateHeader(java.lang.String, long)

addHeader

public void addHeader(String arg0,
                      String arg1)
See Also:
HttpServletResponse.addHeader(java.lang.String, java.lang.String)

addIntHeader

public void addIntHeader(String arg0,
                         int arg1)
See Also:
HttpServletResponse.addIntHeader(java.lang.String, int)

containsHeader

public boolean containsHeader(String arg0)
See Also:
HttpServletResponse.containsHeader(java.lang.String)

encodeRedirectURL

public String encodeRedirectURL(String arg0)
See Also:
HttpServletResponse.encodeRedirectURL(java.lang.String)

encodeURL

public String encodeURL(String arg0)
See Also:
HttpServletResponse.encodeURL(java.lang.String)

getLocale

public Locale getLocale()
See Also:
ServletResponse.getLocale()

sendError

public void sendError(int arg0,
                      String arg1)
               throws IOException
Throws:
IOException
See Also:
HttpServletResponse.sendError(int, java.lang.String)

sendError

public void sendError(int arg0)
               throws IOException
Throws:
IOException
See Also:
HttpServletResponse.sendError(int)

setDateHeader

public void setDateHeader(String arg0,
                          long arg1)
See Also:
HttpServletResponse.setDateHeader(java.lang.String, long)

setIntHeader

public void setIntHeader(String arg0,
                         int arg1)
See Also:
HttpServletResponse.setIntHeader(java.lang.String, int)

setLocale

public void setLocale(Locale arg0)
See Also:
ServletResponse.setLocale(java.util.Locale)

getOutputStream

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

Throws:
IOException

getWriter

public PrintWriter getWriter()
                      throws IOException
Return the PrintWriter

Throws:
IOException

setContentType

public void setContentType(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 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 String toString()
Return all data that has been written to the PrintWriter.


getXMLEncoding

public static final String getXMLEncoding(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)

Returns:
The XML Encoding, or null if the String was not recognized as XML (no <?xml> header found)
Since:
MMBase-1.7.1
See Also:
getXMLEncoding(byte[])

getXMLEncoding

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

Returns:
The XML Encoding, or null if the String was not recognized as XML (not <?xml> header found)
Since:
MMBase-1.7.1
See Also:
getXMLEncoding(String)

getEncoding

public static String getEncoding(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 String getDefaultEncoding(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


MMBase build 1.8.1.20060716