cmsflexresponse.java
来自「java 编写的程序」· Java 代码 · 共 801 行 · 第 1/3 页
JAVA
801 行
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/cache/Attic/CmsFlexResponse.java,v $
* Date : $Date: 2002/05/10 21:07:31 $
* Version: $Revision: 1.1.2.1.2.1 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2002 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.flex.cache;
import java.util.Map;
import java.util.ArrayList;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* A wrapper class for a HttpServletRequest that controls the Flex cache.
*
* @author Alexander Kandzior (a.kandzior@alkacon.com)
* @version $Revision: 1.1.2.1.2.1 $
*/
public class CmsFlexResponse extends javax.servlet.http.HttpServletResponseWrapper {
/** The wrapped ServletResponse */
private HttpServletResponse m_res = null;
/** The cached entry that is constructed from this response */
private CmsFlexCacheEntry m_cachedEntry = null;
/** A special wrapper class for a ServletOutputStream */
private com.opencms.flex.cache.CmsFlexResponse.CmsServletOutputStream m_out;
/** A printwriter that writes in the m_out stream */
private java.io.PrintWriter m_writer = null;
/** Indicates that the OutputStream m_out should write ONLY in the buffer */
private boolean m_writeOnlyToBuffer;
/** Indicates that parent stream is writing only in the buffer */
private boolean m_parentWritesOnlyToBuffer;
/** A list of include calls that origin from this page, i.e. these are sub elements of this element */
private java.util.List m_includeList = null;
/** A list of results from the inclusions, needed because of JSP buffering */
private java.util.List m_includeResults = null;
/** Byte array used for "cached leafs" optimization */
private byte[] m_cacheBytes = null;
/** The CmsFlexCacheKey for this response */
private CmsFlexCacheKey m_key = null;
/** Map to save all response headers (including sub-elements) in */
private Map m_headers;
/** Map to save response headers belonging to a single include call in */
private Map m_buffer_headers;
/** Indicates if this response is suspended (probably because of a redirect) */
private boolean m_suspended = false;
/** String to hold a buffered redirect target */
private String m_buffer_redirect = null;
/** Indicates if caching is required, will always be true if m_writeOnlyToBuffer is true */
private boolean m_cachingRequired = false;
/** Indicates if this element is currently in include mode, i.e. processing a sub-element */
private boolean m_includeMode = false;
/** Static string to indicate a header is "set" in the header maps */
public static final String C_SETHEADER = "[setHeader]";
/** Flag for debugging output */
private static boolean DEBUG = false;
/**
* Constructor for the CmsFlexResponse.
* This one is usually used for the "Top" response.
*
* @param res The HttpServletResponse to wrap
* @param streaming Indicates if streaming should be enabled or not
*/
public CmsFlexResponse(HttpServletResponse res, boolean streaming) {
super(res);
m_res = res;
m_out = null;
m_parentWritesOnlyToBuffer = ! streaming;
setOnlyBuffering(m_parentWritesOnlyToBuffer);
m_headers = new java.util.HashMap(37);
m_buffer_headers = new java.util.HashMap(17);
}
/**
* Constructor for the CmsFlexResponse.
* This one is usually used to wrap responses for further include calls in OpenCms.
*
* @param res The CmsFlexResponse to wrap
*/
public CmsFlexResponse(CmsFlexResponse res) {
super(res);
m_res = res;
m_out = null;
m_parentWritesOnlyToBuffer = res.hasIncludeList();
setOnlyBuffering(m_parentWritesOnlyToBuffer);
m_headers = new java.util.HashMap(37);
m_buffer_headers = new java.util.HashMap(17);
}
/**
* Returns the top wrapped response, i.e. the first response wrapped
* that is not of type CmsFlexResponse.
*
* @return The top wrapped response.
*/
private HttpServletResponse getTopResponse() {
if (m_res instanceof CmsFlexResponse) {
return ((CmsFlexResponse)m_res).getTopResponse();
} else {
return m_res;
}
}
/**
* 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.<p>
*
* If buffering is on, nothing is written to the output stream
* even if streaming for this resonse is enabled.
*
* @param value The value to set
*/
public void setOnlyBuffering(boolean value) {
m_writeOnlyToBuffer = value;
if (m_writeOnlyToBuffer) {
setCmsCachingRequired(true);
}
}
/**
* 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.
*
* @param value The value to set
*/
void setCmsCachingRequired(boolean value) {
m_cachingRequired = value || m_writeOnlyToBuffer;
}
/**
* 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.
*
* @param value The value to set
*/
void setCmsIncludeMode(boolean value) {
m_includeMode = value;
}
/**
* This 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.<p>
*
* Currently, a response is only suspended if it is redirected.
*
* @return true if the response is suspended, false otherwise
*/
public boolean isSuspended() {
return m_suspended;
}
/**
* 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.<p>
*
* @param value The value to set
*/
void setSuspended(boolean value) {
m_suspended = value;
if (m_res instanceof CmsFlexResponse) {
((CmsFlexResponse)m_res).setSuspended(value);
}
}
/**
* Provides access to the header cache of the top wrapper.
*
* @return The map of cached headers.
*/
public Map getHeaders() {
return m_headers;
}
/**
* Adds some bytes to the list of include results.
* Should be used only in inclusion-scenarios
* like the JSP cms:include tag processing.
*
* @param result The byte array to add
*/
public void addToIncludeResults(byte[] result) {
if (m_includeResults == null) {
m_includeResults = new ArrayList(10);
}
m_includeResults.add(result);
}
/**
* Adds an inclusion target to the list of include results.
* Should be used only in inclusion-scenarios
* like the JSP cms:include tag processing.
*
* @param target The include target name to add
*/
public void addToIncludeList(String target) {
if (m_includeList == null) {
m_includeList = new ArrayList(10);
}
m_includeList.add(target);
}
/**
* 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.
*
* @return true if this response has an include list, false otherwise
*/
public boolean hasIncludeList() {
return m_includeList != null;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?