org.mmbase.util
Class GenericResponseWrapper

java.lang.Object
  extended by javax.servlet.ServletResponseWrapper
      extended by javax.servlet.http.HttpServletResponseWrapper
          extended by org.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 41036 2010-02-15 22:30:54Z michiel $
Author:
Kees Jongenburger, Johannes Verelst, Michiel Meeuwissen

Field Summary
protected  String redirected
           
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_FOUND, 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.
 String getRedirected()
           
 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, getContentType, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, 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, getContentType, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLength
 

Field Detail

TEXT_XML_DEFAULT_CHARSET

public static String TEXT_XML_DEFAULT_CHARSET

redirected

protected String redirected
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
Specified by:
sendRedirect in interface HttpServletResponse
Overrides:
sendRedirect in class HttpServletResponseWrapper
Throws:
IOException

getRedirected

public String getRedirected()
Since:
MMBase-1.8.5

setStatus

public void setStatus(int s)
Specified by:
setStatus in interface HttpServletResponse
Overrides:
setStatus in class HttpServletResponseWrapper

addCookie

public void addCookie(Cookie c)
Specified by:
addCookie in interface HttpServletResponse
Overrides:
addCookie in class HttpServletResponseWrapper

setHeader

public void setHeader(String header,
                      String value)
Specified by:
setHeader in interface HttpServletResponse
Overrides:
setHeader in class HttpServletResponseWrapper

addDateHeader

public void addDateHeader(String arg0,
                          long arg1)
Specified by:
addDateHeader in interface HttpServletResponse
Overrides:
addDateHeader in class HttpServletResponseWrapper
See Also:
HttpServletResponse.addDateHeader(java.lang.String, long)

addHeader

public void addHeader(String arg0,
                      String arg1)
Specified by:
addHeader in interface HttpServletResponse
Overrides:
addHeader in class HttpServletResponseWrapper
See Also:
HttpServletResponse.addHeader(java.lang.String, java.lang.String)

addIntHeader

public void addIntHeader(String arg0,
                         int arg1)
Specified by:
addIntHeader in interface HttpServletResponse
Overrides:
addIntHeader in class HttpServletResponseWrapper
See Also:
HttpServletResponse.addIntHeader(java.lang.String, int)

containsHeader

public boolean containsHeader(String arg0)
Specified by:
containsHeader in interface HttpServletResponse
Overrides:
containsHeader in class HttpServletResponseWrapper
See Also:
HttpServletResponse.containsHeader(java.lang.String)

encodeRedirectURL

public String encodeRedirectURL(String arg0)
Specified by:
encodeRedirectURL in interface HttpServletResponse
Overrides:
encodeRedirectURL in class HttpServletResponseWrapper
See Also:
HttpServletResponse.encodeRedirectURL(java.lang.String)

encodeURL

public String encodeURL(String arg0)
Specified by:
encodeURL in interface HttpServletResponse
Overrides:
encodeURL in class HttpServletResponseWrapper
See Also:
HttpServletResponse.encodeURL(java.lang.String)

getLocale

public Locale getLocale()
Specified by:
getLocale in interface ServletResponse
Overrides:
getLocale in class ServletResponseWrapper
See Also:
ServletResponse.getLocale()

sendError

public void sendError(int arg0,
                      String arg1)
               throws IOException
Specified by:
sendError in interface HttpServletResponse
Overrides:
sendError in class HttpServletResponseWrapper
Throws:
IOException
See Also:
HttpServletResponse.sendError(int, java.lang.String)

sendError

public void sendError(int arg0)
               throws IOException
Specified by:
sendError in interface HttpServletResponse
Overrides:
sendError in class HttpServletResponseWrapper
Throws:
IOException
See Also:
HttpServletResponse.sendError(int)

setDateHeader

public void setDateHeader(String arg0,
                          long arg1)
Specified by:
setDateHeader in interface HttpServletResponse
Overrides:
setDateHeader in class HttpServletResponseWrapper
See Also:
HttpServletResponse.setDateHeader(java.lang.String, long)

setIntHeader

public void setIntHeader(String arg0,
                         int arg1)
Specified by:
setIntHeader in interface HttpServletResponse
Overrides:
setIntHeader in class HttpServletResponseWrapper
See Also:
HttpServletResponse.setIntHeader(java.lang.String, int)

setLocale

public void setLocale(Locale arg0)
Specified by:
setLocale in interface ServletResponse
Overrides:
setLocale in class ServletResponseWrapper
See Also:
ServletResponse.setLocale(java.util.Locale)

getOutputStream

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

Specified by:
getOutputStream in interface ServletResponse
Overrides:
getOutputStream in class ServletResponseWrapper
Throws:
IOException

getWriter

public PrintWriter getWriter()
                      throws IOException
Return the PrintWriter

Specified by:
getWriter in interface ServletResponse
Overrides:
getWriter in class ServletResponseWrapper
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.

Specified by:
setContentType in interface ServletResponse
Overrides:
setContentType in class ServletResponseWrapper

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

Specified by:
getCharacterEncoding in interface ServletResponse
Overrides:
getCharacterEncoding in class ServletResponseWrapper

determinXMLEncoding

protected byte[] determinXMLEncoding()

toString

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

Overrides:
toString in class Object

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 2.0-SNAPSHOT - null