cmsflexrequest.java
来自「java 编写的程序」· Java 代码 · 共 408 行 · 第 1/2 页
JAVA
408 行
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/flex/cache/Attic/CmsFlexRequest.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;
/**
* 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 Alexander Kandzior (a.kandzior@alkacon.com)
* @version $Revision: 1.1.2.1.2.1 $
*/
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;
/** Debug - flag */
private static boolean DEBUG = false;
/** Set of all include calls (to prevent an endless inclusion loop) */
private java.util.Set m_includeCalls;
/** 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;
if (paras != null) {
java.util.List l = java.util.Arrays.asList(paras);
nocachepara = l.contains("nocache");
boolean p_on = l.contains("online");
boolean p_off = l.contains("offline");
if (l.contains("clearcache")) {
if (! (p_on || p_off)) {
m_cache.clear(m_cms);
} else {
if (p_on) m_cache.clearOnline(m_cms);
if (p_off) m_cache.clearOffline(m_cms);
}
} else if (l.contains("clearentries")) {
if (! (p_on || p_off)) {
m_cache.clearEntries(m_cms);
} else {
if (p_on) m_cache.clearOnlineEntries(m_cms);
if (p_off) m_cache.clearOfflineEntries(m_cms);
}
}
}
if (nocachepara) {
try {
nocachepara = nocachepara && m_cms.getRequestContext().isAdmin();
} catch (Exception e) {
nocachepara = false;
}
}
m_canCache = ((m_isOnline || m_cache.cacheOffline()) && ! nocachepara);
}
/**
* 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_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.
*
* @return The CmsObject that belongs to the request.
*/
public com.opencms.file.CmsObject getCmsObject() {
return m_cms;
}
/**
* The CmsFlexCache where all results from this request will be cached in.
* This is public so that pages like the Flex Cache Administration page
* have a way to access the cache object.
*
* @return The cache where the results will be stored.
*/
public CmsFlexCache getCmsCache() {
return m_cache;
}
/**
* This method provides access to the top-level CmsFile of the request,
* i.e. the CmsFile that is identical to the file requested by the user,
* not he current included element.
*
* @return The requested top-level CmsFile
*/
public com.opencms.file.CmsFile getCmsFile() {
return m_file;
}
/**
* Returns the resource currently requested.
* This might be the name of an included resource that is currently processed.
*
* @return The resource target of this request.
*/
public String getCmsResource() {
return m_resource;
}
/** Convert (if necessary) and return the absolute URI that represents the
* resource referenced by this possibly relative URI for this request.
* Adjust for resources in the OpenCms VFS by cutting of servlet context
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?