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

📄 cmsrequestcontext.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/file/CmsRequestContext.java,v $
* Date   : $Date: 2002/02/05 09:07:02 $
* Version: $Revision: 1.47 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  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.file;

import java.util.*;
import javax.servlet.http.*;

import com.opencms.core.*;
import com.opencms.template.cache.*;

/**
 * This class provides access to the CmsRequestContext.
 * <br>
 * In the CmsRequestContext class are all methods bundled, which can inform about the
 * current request properties, like  the url or uri of the request.
 * <p>
 *
 * @author Andreas Schouten
 * @author Michael Emmerich
 * @author Anders Fugmann
 * @author Alexander Lucas
 *
 * @version $Revision: 1.47 $ $Date: 2002/02/05 09:07:02 $
 *
 */
public class CmsRequestContext implements I_CmsConstants {

    /**
     * The rb to get access to the OpenCms.
     */
    private I_CmsResourceBroker m_rb;

    /**
     * The current CmsRequest.
     */
    private I_CmsRequest m_req;

    /**
     * The current CmsResponse.
     */
    private I_CmsResponse m_resp;

    /**
     * The current user.
     */
    private CmsUser m_user;

    /**
     * The current group of the user.
     */
    private CmsGroup m_currentGroup;

    /**
     * The current project.
     */
    private CmsProject m_currentProject;

    /**
     * Is this response streaming?
     */
    private boolean m_streaming = true;

    /**
     * In export mode the links in pages will be stored in this vector
     * for further processing.
     */
    private Vector m_links;

    /**
     * In export mode this vector is used to store all dependencies this request
     * may have. It is saved to the database and if one of the dependencies changes
     * the request will be exported again.
     */
    private Vector m_dependencies;

    /** Starting point for element cache */
    private CmsElementCache m_elementCache = null;

    /** Current languages */
    private Vector m_language = new Vector();

    /**
     * The name of the root, e.g. /site_a/vfs
     */
    private String m_siteRoot = C_DEFAULT_SITE+C_ROOTNAME_VFS;

    /**
     * The default constructor.
     *
     */
    public CmsRequestContext() {
        super();
    }

    /**
     * adds a link for the static export.
     */
    public void addLink(String link){
        m_links.add(link);
    }

    /**
     * returns all links that the templatemechanism has registered.
     */
    public Vector getLinkVector(){
        return m_links;
    }

    /**
     * adds a dependency.
     * @param dependency. The rootpath of the resource.
     */
    public void addDependency(String rootName){
        m_dependencies.add(rootName);
    }

    /**
     * returns all dependencies the templatemechanism has registered.
     */
    public Vector getDependencies(){
        return m_dependencies;
    }

    /**
     * Returns the current folder object.
     *
     * @return the current folder object.
     *
     * @exception CmsException if operation was not successful.
     */
    public CmsFolder currentFolder() throws CmsException {
        // truncate the filename from the pathinformation
        String folderName = getUri().substring(0, getUri().lastIndexOf("/") + 1);
        return (m_rb.readFolder(currentUser(), currentProject(), getSiteRoot(folderName), ""));
    }
    /**
     * Returns the current group of the current user.
     *
     * @return the current group of the current user.
     */
    public CmsGroup currentGroup() {
        return(m_currentGroup);
    }
    /**
     * Returns the current project of the current user.
     *
     * @return the current project of the current user.
     */
    public CmsProject currentProject() {
        return m_currentProject;
    }
    /**
     * Returns the current user object.
     *
     * @return the current user object.
     */
    public CmsUser currentUser() {
        return(m_user);
    }
   /**
    * Gets the name of the requested file without any path-information.
    *
    * @return the requested filename.
    */
    public String getFileUri() {
        String uri = m_req.getRequestedResource();
        uri=uri.substring(uri.lastIndexOf("/")+1);
        return uri;
    }
    /**
     * Gets the current request, if availaible.
     *
     * @return the current request, if availaible.
     */
    public I_CmsRequest getRequest() {
        return( m_req );
    }
    /**
     * Gets the current response, if availaible.
     *
     * @return the current response, if availaible.
     */
    public I_CmsResponse getResponse() {
        return( m_resp );
    }
    /**
     * Gets the Session for this request.
     * <br>
     * This method should be used instead of the originalRequest.getSession() method.
     * @param value indicates, if a session should be created when a session for the particular client does not already exist.
     * @return the CmsSession, or <code>null</code> if no session already exists and value was set to <code>false</code>
     *
     */
    public I_CmsSession getSession(boolean value) {
        HttpSession session = ((HttpServletRequest)m_req.getOriginalRequest()).getSession(value);
        if(session != null) {
            return (I_CmsSession) new CmsSession(session);
        } else {
            return null;
        }
    }
    /**
     * Gets the uri for the requested resource.
     * <p>
     * For a http request, the name of the resource is extracted as follows:<br>
     * <CODE>http://{servername}/{servletpath}/{path to the cms resource}</CODE><br>
     * In the following example:<br>
     * <CODE>http://my.work.server/servlet/opencms/system/def/explorer</CODE><br>
     * the requested resource is <CODE>/system/def/explorer</CODE>.

⌨️ 快捷键说明

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