⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsflexresponse.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/cache/Attic/CmsFlexResponse.java,v $
 * Date   : $Date: 2003/05/13 13:18:20 $
 * Version: $Revision: 1.16.2.1 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (C) 2002 - 2003 Alkacon Software (http://www.alkacon.com)
 *
 * 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 Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project 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 com.opencms.core.A_OpenCms;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

/**
 * Wrapper class for a HttpServletResponse.<p>
 *
 * This class wrapps the standard HttpServletResponse so that it's output can be delivered to
 * the CmsFlexCache.
 *
 * @author  Alexander Kandzior (a.kandzior@alkacon.com)
 * @version $Revision: 1.16.2.1 $
 */
public class CmsFlexResponse extends 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 CmsFlexResponse.CmsServletOutputStream m_out;
    
    /** The CmsFlexController for this response */
    private CmsFlexController m_controller = null;
        
    /** 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 List m_includeList = null;
    
    /** A list of parameters that belong to the include calls */
    private List m_includeListParameters = null;
    
    /** A list of results from the inclusions, needed because of JSP buffering */
    private 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 final boolean DEBUG = false;
    
    /** The cache delimiter char */
    public static final char C_FLEX_CACHE_DELIMITER = (char)0;
    
    /** The encoding to use for the response */
    private String m_encoding;
    
    /** Flag to indicate if this is the top level element or an included sub - element */ 
    private boolean m_isTopElement;     
    
    /** 
     * Constructor for the CmsFlexResponse,
     * this variation is usually used for the "Top" response.<p>
     *
     * @param res the HttpServletResponse to wrap
     * @param controller the controller to use
     * @param streaming indicates if streaming should be enabled or not
     * @param isTopElement indicates if this is the top element of an include cascade
     */
    public CmsFlexResponse(HttpServletResponse res, CmsFlexController controller, boolean streaming, boolean isTopElement) {
        super(res);
        m_res = res;
        m_controller = controller;
        m_out = null;
        m_encoding = controller.getCmsObject().getRequestContext().getEncoding();
        m_isTopElement = isTopElement;
        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 variation one is usually used to wrap responses for further include calls in OpenCms.<p>
     *
     * @param res the CmsFlexResponse to wrap     
     * @param controller the controller to use
     */
    public CmsFlexResponse(HttpServletResponse res, CmsFlexController controller) {
        super(res);
        m_res = res;
        m_controller = controller;
        m_out = null;
        m_encoding = controller.getCurrentResponse().getEncoding();
        m_isTopElement = controller.getCurrentResponse().isTopElement();        
        m_parentWritesOnlyToBuffer = controller.getCurrentResponse().hasIncludeList();
        setOnlyBuffering(m_parentWritesOnlyToBuffer);
        m_headers = new java.util.HashMap(37);
        m_buffer_headers = new java.util.HashMap(17);
    }    
    
    /**
     * Returns the value of the encoding used for this response.<p>
     * 
     * @return the value of the encoding used for this response
     */
    public String getEncoding() {
        return m_encoding;
    }
    
    /**
     * Returns <code>true</code> if this response has been constructed for the 
     * top level element of this request, <code>false</code> if it was 
     * constructed for an included sub-element.<p>
     * 
     * @return <code>true</code> if this response has been constructed for the 
     * top level element of this request, <code>false</code> if it was 
     * constructed for an included sub-element.
     */
    public boolean isTopElement() {
        return m_isTopElement;        
    }
    
    /** 
     * Sets buffering status of the response.<p>
     * 
     * 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.<p>
     *
     * @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.<p>
     * 
     * 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.<p>
     *
     * @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.<p>
     * 
     * 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.<p>
     *
     * @param value the value to set     
     */
    void setCmsIncludeMode(boolean value) {
        m_includeMode = value;
    }
    
    /** 
     * This flag indicates if the response is suspended or not.<p>
     * 
     * 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.<p>
     *
     * @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.<p>
     * 
     * 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;
    }
        
    /**
     * Provides access to the header cache of the top wrapper.<p>
     *
     * @return the Map of cached headers
     */
    public Map getHeaders() {
        return m_headers;
    }    
        
    /**
     * Adds some bytes to the list of include results.<p>
     * 
     * Should be used only in inclusion-scenarios 
     * like the JSP cms:include tag processing.<p>
     * 
     * @param result the byte array to add
     */
    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.<p>
     * 
     * Should be used only in inclusion-scenarios
     * like the JSP cms:include tag processing.<p>
     *
     * @param target the include target name to add
     */
    public void addToIncludeList(String target, Map parameterMap) {
        if (m_includeList == null) {
            m_includeList = new ArrayList(10);
            m_includeListParameters = new ArrayList(10);
        }        
        m_includeListParameters.add(parameterMap);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -