Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.opencms.flex.cache
Class CmsFlexResponse  view CmsFlexResponse download CmsFlexResponse.java

java.lang.Object
  extended byjavax.servlet.ServletResponseWrapper
      extended byjavax.servlet.http.HttpServletResponseWrapper
          extended bycom.opencms.flex.cache.CmsFlexResponse
All Implemented Interfaces:
javax.servlet.http.HttpServletResponse, javax.servlet.ServletResponse

public class CmsFlexResponse
extends javax.servlet.http.HttpServletResponseWrapper

Wrapper class for a HttpServletResponse.

This class wrapps the standard HttpServletResponse so that it's output can be delivered to the CmsFlexCache.

Version:
$Revision: 1.16.2.1 $

Nested Class Summary
private  class CmsFlexResponse.CmsServletOutputStream
          Wrapped implementation of the ServletOutputStream.
 
Field Summary
static char C_FLEX_CACHE_DELIMITER
          The cache delimiter char
static java.lang.String C_SETHEADER
          Static string to indicate a header is "set" in the header maps
private static boolean DEBUG
          Flag for debugging output
private  java.util.Map m_buffer_headers
          Map to save response headers belonging to a single include call in
private  java.lang.String m_buffer_redirect
          String to hold a buffered redirect target
private  byte[] m_cacheBytes
          Byte array used for "cached leafs" optimization
private  CmsFlexCacheEntry m_cachedEntry
          The cached entry that is constructed from this response
private  boolean m_cachingRequired
          Indicates if caching is required, will always be true if m_writeOnlyToBuffer is true
private  CmsFlexController m_controller
          The CmsFlexController for this response
private  java.lang.String m_encoding
          The encoding to use for the response
private  java.util.Map m_headers
          Map to save all response headers (including sub-elements) in
private  java.util.List m_includeList
          A list of include calls that origin from this page, i.e.
private  java.util.List m_includeListParameters
          A list of parameters that belong to the include calls
private  boolean m_includeMode
          Indicates if this element is currently in include mode, i.e.
private  java.util.List m_includeResults
          A list of results from the inclusions, needed because of JSP buffering
private  boolean m_isTopElement
          Flag to indicate if this is the top level element or an included sub - element
private  CmsFlexCacheKey m_key
          The CmsFlexCacheKey for this response
private  CmsFlexResponse.CmsServletOutputStream m_out
          A special wrapper class for a ServletOutputStream
private  boolean m_parentWritesOnlyToBuffer
          Indicates that parent stream is writing only in the buffer
private  javax.servlet.http.HttpServletResponse m_res
          The wrapped ServletResponse
private  boolean m_suspended
          Indicates if this response is suspended (probably because of a redirect)
private  boolean m_writeOnlyToBuffer
          Indicates that the OutputStream m_out should write ONLY in the buffer
private  java.io.PrintWriter m_writer
          A printwriter that writes in the m_out stream
 
Fields inherited from class javax.servlet.ServletResponseWrapper
 
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
CmsFlexResponse(javax.servlet.http.HttpServletResponse res, CmsFlexController controller)
          Constructor for the CmsFlexResponse, this variation one is usually used to wrap responses for further include calls in OpenCms.
CmsFlexResponse(javax.servlet.http.HttpServletResponse res, CmsFlexController controller, boolean streaming, boolean isTopElement)
          Constructor for the CmsFlexResponse, this variation is usually used for the "Top" response.
 
Method Summary
 void addDateHeader(java.lang.String name, long date)
          Method overlodad from the standard HttpServletRequest API.
 void addHeader(java.lang.String name, java.lang.String value)
          Method overlodad from the standard HttpServletRequest API.
private  void addHeaderList(java.util.Map headers, java.lang.String name, java.lang.String value)
          Helper method to add a value in the internal header list.
 void addIntHeader(java.lang.String name, int value)
          Method overlodad from the standard HttpServletRequest API.
 void addToIncludeList(java.lang.String target, java.util.Map parameterMap)
          Adds an inclusion target to the list of include results.
(package private)  void addToIncludeResults(byte[] result)
          Adds some bytes to the list of include results.
(package private)  CmsFlexCacheKey getCmsCacheKey()
          Returns the cache key for to this response.
 java.lang.String getEncoding()
          Returns the value of the encoding used for this response.
 java.util.Map getHeaders()
          Provides access to the header cache of the top wrapper.
 javax.servlet.ServletOutputStream getOutputStream()
          Method overlodad from the standard HttpServletRequest API.
 java.io.PrintWriter getWriter()
          Method overlodad from the standard HttpServletRequest API.
 byte[] getWriterBytes()
          Returns the bytes that have been written on the current writers output stream.
(package private)  boolean hasIncludeList()
          Is used to check if the response has an include list, which indicates a) it is probalbly processing a JSP element and b) it can never be streamed and alwys must be buffered.
private  void initStream()
          Initializes the current responses output stream and the corrosponding print writer.
 boolean isSuspended()
          This flag indicates if the response is suspended or not.
 boolean isTopElement()
          Returns true if this response has been constructed for the top level element of this request, false if it was constructed for an included sub-element.
(package private)  CmsFlexCacheEntry processCacheEntry()
          Generates a CmsFlexCacheEntry from the current response using the stored include results.
static void processHeaders(java.util.Map headers, javax.servlet.http.HttpServletResponse res)
          Process the headers stored in the provided map and add them to the response.
private  void processIncludeList()
          This method is needed to process pages that can NOT be analyzed directly during delivering (like JSP) because they write to their own buffer.
 void sendRedirect(java.lang.String location)
          Method overlodad from the standard HttpServletRequest API.
(package private)  void setCmsCacheKey(CmsFlexCacheKey value)
          Sets the cache key for this response from a pre-calculated cache key.
(package private)  CmsFlexCacheKey setCmsCacheKey(java.lang.String target, java.lang.String value, boolean online)
          Sets the cache key for this response, which is calculated from the provided parameters.
(package private)  void setCmsCachingRequired(boolean value)
          Set caching status for this reponse.
(package private)  void setCmsIncludeMode(boolean value)
          This flag indicates to the response if it is in "include mode" or not.
 void setContentType(java.lang.String type)
          Method overlodad from the standard HttpServletRequest API.
 void setDateHeader(java.lang.String name, long date)
          Method overlodad from the standard HttpServletRequest API.
 void setHeader(java.lang.String name, java.lang.String value)
          Method overlodad from the standard HttpServletRequest API.
private  void setHeaderList(java.util.Map headers, java.lang.String name, java.lang.String value)
          Helper method to set a value in the internal header list.
 void setIntHeader(java.lang.String name, int value)
          Method overlodad from the standard HttpServletRequest API.
 void setOnlyBuffering(boolean value)
          Sets buffering status of the response.
(package private)  void setSuspended(boolean value)
          Sets the suspended status of the response, and also sets the suspend status of all responses wrapping this response.
private  void writeCachedResultToStream(javax.servlet.http.HttpServletResponse res)
          This delivers cached sub-elements back to the stream.
(package private)  void writeToOutputStream(byte[] bytes, boolean useArray)
          Writes some bytes to the current output stream, this method should be called from CmsFlexCacheEntry.service() only.
 
Methods inherited from class javax.servlet.http.HttpServletResponseWrapper
addCookie, containsHeader, encodeRedirectUrl, encodeRedirectURL, encodeUrl, encodeURL, sendError, sendError, setStatus, setStatus
 
Methods inherited from class javax.servlet.ServletResponseWrapper
flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, getResponse, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLength, setLocale, setResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.servlet.ServletResponse
flushBuffer, getBufferSize, getCharacterEncoding, getContentType, getLocale, isCommitted, reset, resetBuffer, setBufferSize, setCharacterEncoding, setContentLength, setLocale
 

Field Detail

m_res

private javax.servlet.http.HttpServletResponse m_res
The wrapped ServletResponse


m_cachedEntry

private CmsFlexCacheEntry m_cachedEntry
The cached entry that is constructed from this response


m_out

private CmsFlexResponse.CmsServletOutputStream m_out
A special wrapper class for a ServletOutputStream


m_controller

private CmsFlexController m_controller
The CmsFlexController for this response


m_writer

private java.io.PrintWriter m_writer
A printwriter that writes in the m_out stream


m_writeOnlyToBuffer

private boolean m_writeOnlyToBuffer
Indicates that the OutputStream m_out should write ONLY in the buffer


m_parentWritesOnlyToBuffer

private boolean m_parentWritesOnlyToBuffer
Indicates that parent stream is writing only in the buffer


m_includeList

private java.util.List m_includeList
A list of include calls that origin from this page, i.e. these are sub elements of this element


m_includeListParameters

private java.util.List m_includeListParameters
A list of parameters that belong to the include calls


m_includeResults

private java.util.List m_includeResults
A list of results from the inclusions, needed because of JSP buffering


m_cacheBytes

private byte[] m_cacheBytes
Byte array used for "cached leafs" optimization


m_key

private CmsFlexCacheKey m_key
The CmsFlexCacheKey for this response


m_headers

private java.util.Map m_headers
Map to save all response headers (including sub-elements) in


m_buffer_headers

private java.util.Map m_buffer_headers
Map to save response headers belonging to a single include call in


m_suspended

private boolean m_suspended
Indicates if this response is suspended (probably because of a redirect)


m_buffer_redirect

private java.lang.String m_buffer_redirect
String to hold a buffered redirect target


m_cachingRequired

private boolean m_cachingRequired
Indicates if caching is required, will always be true if m_writeOnlyToBuffer is true


m_includeMode

private boolean m_includeMode
Indicates if this element is currently in include mode, i.e. processing a sub-element


C_SETHEADER

public static final java.lang.String C_SETHEADER
Static string to indicate a header is "set" in the header maps

See Also:
Constant Field Values

DEBUG

private static final boolean DEBUG
Flag for debugging output

See Also:
Constant Field Values

C_FLEX_CACHE_DELIMITER

public static final char C_FLEX_CACHE_DELIMITER
The cache delimiter char

See Also:
Constant Field Values

m_encoding

private java.lang.String m_encoding
The encoding to use for the response


m_isTopElement

private boolean m_isTopElement
Flag to indicate if this is the top level element or an included sub - element

Constructor Detail

CmsFlexResponse

public CmsFlexResponse(javax.servlet.http.HttpServletResponse res,
                       CmsFlexController controller,
                       boolean streaming,
                       boolean isTopElement)
Constructor for the CmsFlexResponse, this variation is usually used for the "Top" response.


CmsFlexResponse

public CmsFlexResponse(javax.servlet.http.HttpServletResponse res,
                       CmsFlexController controller)
Constructor for the CmsFlexResponse, this variation one is usually used to wrap responses for further include calls in OpenCms.

Method Detail

getEncoding

public java.lang.String getEncoding()
Returns the value of the encoding used for this response.


isTopElement

public boolean isTopElement()
Returns true if this response has been constructed for the top level element of this request, false if it was constructed for an included sub-element.


setOnlyBuffering

public void setOnlyBuffering(boolean value)
Sets buffering status of the response.

This must be done before the first output is written. Buffering is needed to process elements that can not be written directly to the output stream because their sub - elements have to be processed seperatly. Which is so far true only for JSP pages.

If buffering is on, nothing is written to the output stream even if streaming for this resonse is enabled.


setCmsCachingRequired

void setCmsCachingRequired(boolean value)
Set caching status for this reponse.

Will always be set to "true" if setOnlyBuffering() is set to "true". Currently this is an optimization for non - JSP elements that are known not to be cachable.


setCmsIncludeMode

void setCmsIncludeMode(boolean value)
This flag indicates to the response if it is in "include mode" or not.

This is important in case a cache entry is constructed, since the cache entry must not consist of output or headers of the included elements.


isSuspended

public boolean isSuspended()
This flag indicates if the response is suspended or not.

A suspended response mut not write further output to any stream or process a cache entry for itself.

Currently, a response is only suspended if it is redirected.


setSuspended

void setSuspended(boolean value)
Sets the suspended status of the response, and also sets the suspend status of all responses wrapping this response.

A suspended response mut not write further output to any stream or process a cache entry for itself.


getHeaders

public java.util.Map getHeaders()
Provides access to the header cache of the top wrapper.


addToIncludeResults

void addToIncludeResults(byte[] result)
Adds some bytes to the list of include results.

Should be used only in inclusion-scenarios like the JSP cms:include tag processing.


addToIncludeList

public void addToIncludeList(java.lang.String target,
                             java.util.Map parameterMap)
Adds an inclusion target to the list of include results.

Should be used only in inclusion-scenarios like the JSP cms:include tag processing.


hasIncludeList

boolean hasIncludeList()
Is used to check if the response has an include list, which indicates a) it is probalbly processing a JSP element and b) it can never be streamed and alwys must be buffered.


processIncludeList

private void processIncludeList()
This method is needed to process pages that can NOT be analyzed directly during delivering (like JSP) because they write to their own buffer.

So in this case, we don't actually write output of include calls to the stream. Where there are include calls we write a C_FLEX_CACHE_DELIMITER char on the stream to indicate that at this point the output of the include must be placed later. The include targets (resource names) are then saved in the m_includeList.

This method must be called after the complete page has been processed. It will contain the output of the page only (no includes), with C_FLEX_CACHE_DELIMITER chars were the include calls should be placed. What we do here is analyze the output and cut it in parts of byte[] arrays which then are saved in the resulting cache entry. For the includes, we just save the name of the resource in the cache entry.

If caching is disabled this method is just not called.


writeCachedResultToStream

private void writeCachedResultToStream(javax.servlet.http.HttpServletResponse res)
                                throws java.io.IOException
This delivers cached sub-elements back to the stream. Needed to overcome JSP buffering.


processCacheEntry

CmsFlexCacheEntry processCacheEntry()
                              throws java.io.IOException
Generates a CmsFlexCacheEntry from the current response using the stored include results.

In case the results were written only to the buffer until now, they are now re-written on the output stream, with all included elements.


getWriterBytes

public byte[] getWriterBytes()
Returns the bytes that have been written on the current writers output stream.


initStream

private void initStream()
                 throws java.io.IOException
Initializes the current responses output stream and the corrosponding print writer.


writeToOutputStream

void writeToOutputStream(byte[] bytes,
                         boolean useArray)
                   throws java.io.IOException
Writes some bytes to the current output stream, this method should be called from CmsFlexCacheEntry.service() only.


getCmsCacheKey

CmsFlexCacheKey getCmsCacheKey()
Returns the cache key for to this response.


setCmsCacheKey

CmsFlexCacheKey setCmsCacheKey(java.lang.String target,
                               java.lang.String value,
                               boolean online)
                         throws com.opencms.core.CmsException
Sets the cache key for this response, which is calculated from the provided parameters.


setCmsCacheKey

void setCmsCacheKey(CmsFlexCacheKey value)
Sets the cache key for this response from a pre-calculated cache key.


addHeaderList

private void addHeaderList(java.util.Map headers,
                           java.lang.String name,
                           java.lang.String value)
Helper method to add a value in the internal header list.


setHeaderList

private void setHeaderList(java.util.Map headers,
                           java.lang.String name,
                           java.lang.String value)
Helper method to set a value in the internal header list.


getWriter

public java.io.PrintWriter getWriter()
                              throws java.io.IOException
Method overlodad from the standard HttpServletRequest API.


getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws java.io.IOException
Method overlodad from the standard HttpServletRequest API.


sendRedirect

public void sendRedirect(java.lang.String location)
                  throws java.io.IOException
Method overlodad from the standard HttpServletRequest API.


processHeaders

public static void processHeaders(java.util.Map headers,
                                  javax.servlet.http.HttpServletResponse res)
Process the headers stored in the provided map and add them to the response.


setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
Method overlodad from the standard HttpServletRequest API.


addHeader

public void addHeader(java.lang.String name,
                      java.lang.String value)
Method overlodad from the standard HttpServletRequest API.


setDateHeader

public void setDateHeader(java.lang.String name,
                          long date)
Method overlodad from the standard HttpServletRequest API.


addDateHeader

public void addDateHeader(java.lang.String name,
                          long date)
Method overlodad from the standard HttpServletRequest API.


setIntHeader

public void setIntHeader(java.lang.String name,
                         int value)
Method overlodad from the standard HttpServletRequest API.


addIntHeader

public void addIntHeader(java.lang.String name,
                         int value)
Method overlodad from the standard HttpServletRequest API.


setContentType

public void setContentType(java.lang.String type)
Method overlodad from the standard HttpServletRequest API.