<commit_before>/*
* File   : $Source: /alkacon/cvs/opencms/src/com/opencms/flex/cache/Attic/CmsFlexRequest.java,v $
* Date   : $Date: 2002/08/21 11:29:32 $
* Version: $Revision: 1.2 $
*
* 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 com.opencms.flex.CmsEvent;
import com.opencms.flex.I_CmsEventListener;
import java.util.Collections;
import com.opencms.core.A_OpenCms;

/**
 * A wrapper class for a HttpServletRequest.<p>
 *
 * This class wrapps the standard HttpServletRequest so that it's output can be delivered to
 * the CmsFlexCache.
 *
 * @author <NAME> (<EMAIL>)
 * @version $Revision: 1.2 $
 */
public class CmsFlexRequest extends javax.servlet.http.HttpServletRequestWrapper {
    
    /** The wrapped HttpServletRequest */    
    private javax.servlet.http.HttpServletRequest m_req = null;
    
    /** The CmsFlexCache where the result will be cached in, required for the dispatcher */    
    private CmsFlexCache m_cache = null;    
    
    /** The CmsObject that was initialized by the original request, required for the dispatcher */    
    private com.opencms.file.CmsObject m_cms = null;    

    /** The CmsFile that was initialized by the original request, required for URI actions */    
    private com.opencms.file.CmsFile m_file = null;   
    
    /** The requested resource (target resource) */    
    private String m_resource = null;
    
    /** The CmsFlexCacheKey for this request */
    private CmsFlexCacheKey m_key = null;
    
    /** Flag to decide if this request can be cached or not */
    private boolean m_canCache = false;
    
    /** Flag to check if this request is in the online project or not */
    private boolean m_isOnline = false;
    
    /** Flag to force a JSP recompile */
    private boolean m_doRecompile = false; 
    
    /** Debug - flag */
    private static boolean DEBUG = false;
    
    /** Set of all include calls (to prevent an endless inclusion loop) */
    private java.util.Set m_includeCalls;    
    
    public static String C_ATTR_PROCESSED = "com.opencms.flex.cache.CmsFlexRequest.PROCESSED";
        
    /**
     * Creates a new CmsFlexRequest wrapper which is most likley the "Top"
     * request wrapper, i.e. the wrapper that is constructed around the
     * first "real" (not wrapped) request.<p>
     *
     * @param file the CmsFile (target resource) that has been requested
     * @param req The request to wrap
     * @param cache The CmsFlexCache used to store the cached result (needed by the dispatcher)
     * @param cms The CmsObject for this request, containing the user authorization, needed by the dispatcher. 
     */    
    public CmsFlexRequest(javax.servlet.http.HttpServletRequest req, com.opencms.file.CmsFile file, CmsFlexCache cache, com.opencms.file.CmsObject cms) {
        super(req);
        m_req = req;
        m_cache = cache;
        m_cms = cms;
        m_file = file;
        m_resource = file.getAbsolutePath();
        m_includeCalls = java.util.Collections.synchronizedSet(new java.util.HashSet(23));
        try {
            m_isOnline = (m_cms.onlineProject().equals(m_cms.getRequestContext().currentProject()));
        } catch (Exception e) {}        
        String[] paras = req.getParameterValues("_flex");
        boolean nocachepara = false;
        boolean dorecompile = false;
        boolean isAdmin = false;
        if (paras != null) {
            try {
                isAdmin = m_cms.getRequestContext().isAdmin();
            } catch (Exception e) {}
            if (isAdmin) {                        
                java.util.List l = java.util.Arrays.asList(paras);
                String context = (String)req.getAttribute(C_ATTR_PROCESSED);
                boolean firstCall = (context == null);
                if (firstCall) req.setAttribute(C_ATTR_PROCESSED, "true");
                nocachepara = l.contains("nocache");            
                dorecompile = l.contains("recompile");
                boolean p_on = l.contains("online");
                boolean p_off = l.contains("offline");                
                if (l.contains("purge") && firstCall) {
                    // m_cache.purgeJspRepository(m_cms);
                    // m_cache.clear(m_cms);
                    A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_PURGE_JSP_REPOSITORY, new java.util.HashMap(0)));
                    A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ENTRIES))));
                    dorecompile = false;
                } else if ((l.contains("clearcache") || dorecompile) && firstCall) {
                    if (! (p_on || p_off)) {
                        // m_cache.clear(m_cms);
                        A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ALL))));
                    } else {
                        // if (p_on) m_cache.clearOnline(m_cms);
                        // if (p_off) m_cache.clearOffline(m_cms);
                        if (p_on) A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ONLINE_ALL))));
                        if (p_off) A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_OFFLINE_ALL))));
                    }                    
                } else if (l.contains("clearentries") && firstCall) {
                    if (! (p_on || p_off)) {
                        // m_cache.clearEntries(m_cms);
                        A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ENTRIES))));
                    } else {
                        // if (p_on) m_cache.clearOnlineEntries(m_cms);
                        // if (p_off) m_cache.clearOfflineEntries(m_cms);
                        if (p_on) A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ONLINE_ENTRIES))));
                        if (p_off)  A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_OFFLINE_ENTRIES))));              }
                }
            }
        }  
        m_canCache = (((m_isOnline || m_cache.cacheOffline()) && ! nocachepara) || dorecompile);
        m_doRecompile = dorecompile;
    }
        
    /** 
     * Constructs a new wrapper layer around a (already wrapped) CmsFlexRequest.
     *
     * @param req The request to be wrapped
     * @param resource The target resource that has been requested
     */    
    public CmsFlexRequest(CmsFlexRequest req, String resource) {
        super(req);
        m_req = req;
        m_cache = req.getCmsCache();
        m_cms = req.getCmsObject();
        m_file = req.getCmsFile();
        m_resource = toAbsolute(resource);
        m_isOnline = req.isOnline();
        m_canCache = req.isCacheable();
        m_doRecompile = req.isDoRecompile();
        m_includeCalls = req.getCmsIncludeCalls();        
    }
    
    /** 
     * This returns the "Top" request, i.e. the first wrapped
     * request that is not of type CmsFlexRequest.
     * This is needed for access to the requestDispatcher
     * of this top request, which is used to access external 
     * resources (like JSP files that must reside in the file system).
     *
     * @return The top request
     */    
    public javax.servlet.http.HttpServletRequest getCmsTopRequest() {
        if (m_req instanceof CmsFlexRequest) {
            return ((CmsFlexRequest)m_req).getCmsTopRequest();
        } else {
            return m_req;
        }
    }

    /** 
     * The CmsObject is needed for all access to the OpenCms VFS.<commit_msg>Removed some old code, added optional debug output<commit_after>/*
* File   : $Source: /alkacon/cvs/opencms/src/com/opencms/flex/cache/Attic/CmsFlexRequest.java,v $
* Date   : $Date: 2002/08/30 14:05:14 $
* Version: $Revision: 1.3 $
*
* 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 com.opencms.flex.CmsEvent;
import com.opencms.flex.I_CmsEventListener;
import java.util.Collections;
import com.opencms.core.A_OpenCms;

/**
 * A wrapper class for a HttpServletRequest.<p>
 *
 * This class wrapps the standard HttpServletRequest so that it's output can be delivered to
 * the CmsFlexCache.
 *
 * @author <NAME> (<EMAIL>)
 * @version $Revision: 1.3 $
 */
public class CmsFlexRequest extends javax.servlet.http.HttpServletRequestWrapper {
    
    /** The wrapped HttpServletRequest */    
    private javax.servlet.http.HttpServletRequest m_req = null;
    
    /** The CmsFlexCache where the result will be cached in, required for the dispatcher */    
    private CmsFlexCache m_cache = null;    
    
    /** The CmsObject that was initialized by the original request, required for the dispatcher */    
    private com.opencms.file.CmsObject m_cms = null;    

    /** The CmsFile that was initialized by the original request, required for URI actions */    
    private com.opencms.file.CmsFile m_file = null;   
    
    /** The requested resource (target resource) */    
    private String m_resource = null;
    
    /** The CmsFlexCacheKey for this request */
    private CmsFlexCacheKey m_key = null;
    
    /** Flag to decide if this request can be cached or not */
    private boolean m_canCache = false;
    
    /** Flag to check if this request is in the online project or not */
    private boolean m_isOnline = false;
    
    /** Flag to force a JSP recompile */
    private boolean m_doRecompile = false; 
    
    /** Debug - flag */
    private static boolean DEBUG = false;
    
    /** Set of all include calls (to prevent an endless inclusion loop) */
    private java.util.Set m_includeCalls;    
    
    public static String C_ATTR_PROCESSED = "com.opencms.flex.cache.CmsFlexRequest.PROCESSED";
        
    /**
     * Creates a new CmsFlexRequest wrapper which is most likley the "Top"
     * request wrapper, i.e. the wrapper that is constructed around the
     * first "real" (not wrapped) request.<p>
     *
     * @param file the CmsFile (target resource) that has been requested
     * @param req The request to wrap
     * @param cache The CmsFlexCache used to store the cached result (needed by the dispatcher)
     * @param cms The CmsObject for this request, containing the user authorization, needed by the dispatcher. 
     */    
    public CmsFlexRequest(javax.servlet.http.HttpServletRequest req, com.opencms.file.CmsFile file, CmsFlexCache cache, com.opencms.file.CmsObject cms) {
        super(req);
        m_req = req;
        m_cache = cache;
        m_cms = cms;
        m_file = file;
        m_resource = file.getAbsolutePath();
        m_includeCalls = java.util.Collections.synchronizedSet(new java.util.HashSet(23));
        try {
            m_isOnline = (m_cms.onlineProject().equals(m_cms.getRequestContext().currentProject()));
        } catch (Exception e) {}        
        String[] paras = req.getParameterValues("_flex");
        boolean nocachepara = false;
        boolean dorecompile = false;
        boolean isAdmin = false;
        if (paras != null) {
            try {
                isAdmin = m_cms.getRequestContext().isAdmin();
            } catch (Exception e) {}
            if (isAdmin) {                        
                java.util.List l = java.util.Arrays.asList(paras);
                String context = (String)req.getAttribute(C_ATTR_PROCESSED);
                boolean firstCall = (context == null);
                if (firstCall) req.setAttribute(C_ATTR_PROCESSED, "true");
                nocachepara = l.contains("nocache");            
                dorecompile = l.contains("recompile");
                boolean p_on = l.contains("online");
                boolean p_off = l.contains("offline");                
                if (l.contains("purge") && firstCall) {
                    A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_PURGE_JSP_REPOSITORY, new java.util.HashMap(0)));
                    A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ENTRIES))));
                    dorecompile = false;
                } else if ((l.contains("clearcache") || dorecompile) && firstCall) {
                    if (! (p_on || p_off)) {
                        A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ALL))));
                    } else {
                        if (p_on) A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ONLINE_ALL))));
                        if (p_off) A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_OFFLINE_ALL))));
                    }                    
                } else if (l.contains("clearentries") && firstCall) {
                    if (! (p_on || p_off)) {
                        A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ENTRIES))));
                    } else {
                        if (p_on) A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_ONLINE_ENTRIES))));
                        if (p_off)  A_OpenCms.fireCmsEvent(new CmsEvent(cms, I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, Collections.singletonMap("action", new Integer(CmsFlexCache.C_CLEAR_OFFLINE_ENTRIES))));              
                    }
                }
            }
        }  
        m_canCache = (((m_isOnline || m_cache.cacheOffline()) && ! nocachepara) || dorecompile);
        m_doRecompile = dorecompile;
        if (DEBUG) System.err.println("[FlexRequest] Constructing new Flex request for resource: " + m_resource);
    }
        
    /** 
     * Constructs a new wrapper layer around a (already wrapped) CmsFlexRequest.
     *
     * @param req The request to be wrapped
     * @param resource The target resource that has been requested
     */    
    public CmsFlexRequest(CmsFlexRequest req, String resource) {
        super(req);
        m_req = req;
        m_cache = req.getCmsCache();
        m_cms = req.getCmsObject();
        m_file = req.getCmsFile();
        m_resource = toAbsolute(resource);
        m_isOnline = req.isOnline();
        m_canCache = req.isCacheable();
        m_doRecompile = req.isDoRecompile();
        m_includeCalls = req.getCmsIncludeCalls();        
        if (DEBUG) System.err.println("[FlexRequest] Re-using Flex request for resource: " + m_resource);
    }
    
    /** 
     * This returns the "Top" request, i.e. the first wrapped
     * request that is not of type CmsFlexRequest.
     * This is needed for access to the requestDispatcher
     * of this top request, which is used to access external 
     * resources (like JSP files that must reside in the file system).
     *
     * @return The top request
     */    
    public javax.servlet.http.HttpServletRequest getCmsTopRequest() {
        if (m_req instanceof CmsFlexRequest) {
            return ((CmsFlexRequest)m_req).getCmsTopRequest();
        } else {
            return m_req;
        }
    }

    /** 
     * The CmsObject is needed for all access to the OpenCms VFS.
{'fraction_non_alphanumeric': 0.09309107222969942, 'fraction_numerical': 0.004598474652310453, 'mean_word_length': 2.4877762566008212, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2486217', 'n_tokens_mistral': 5409, 'n_tokens_neox': 5167, 'n_words': 1433}