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

📄 cmsrequestcontext.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * </P>
     *
     * @return the path to the requested resource.
     */
    public String getUri() {
        if( m_req != null ) {
            return( m_req.getRequestedResource() );
        } else {
            return( C_ROOT );
        }
    }
    /**
     * Initializes this RequestContext.
     *
     * @param req the CmsRequest.
     * @param resp the CmsResponse.
     * @param user the current user for this request.
     * @param currentGroup the current group for this request.
     * @param currentProjectId the id of the current project for this request.
     * @param streaming <code>true</code> if streaming should be enabled for this response, <code>false</code> otherwise.
     * @param elementCache Starting point for the element cache or <code>null</code> if the element cache should be disabled.
     *
     * @exception CmsException if operation was not successful.
     */
    void init(I_CmsResourceBroker rb, I_CmsRequest req, I_CmsResponse resp,
              String user, String currentGroup, int currentProjectId, boolean streaming, CmsElementCache elementCache)
        throws CmsException {
        m_rb = rb;
        m_req = req;
        m_resp = resp;
        m_links = new Vector();
        m_dependencies = new Vector();

        try {
            m_user = m_rb.readUser(null, null, user);
        } catch (CmsException ex){
        }
        // if no user found try to read webUser
        if (m_user == null) {
            m_user = m_rb.readWebUser(null, null, user);
        }

        // check, if the user is disabled
        if( m_user.getDisabled() == true ) {
            m_user = null;
        }

        // set current project, group and streaming proerties for this request
        try {
            setCurrentProject(currentProjectId);
        } catch(CmsException exc) {
            // there was a problem to set the needed project - using the online one
            setCurrentProject(I_CmsConstants.C_PROJECT_ONLINE_ID);
        }
        m_currentGroup = m_rb.readGroup(m_user, m_currentProject, currentGroup);
        m_streaming = streaming;
        m_elementCache = elementCache;

        // Analyze the user's preferred languages coming with the request
        if(req != null) {
            try{
                HttpServletRequest httpReq = (HttpServletRequest)req.getOriginalRequest();
                String accLangs = null;
                if(httpReq != null){
                    accLangs = httpReq.getHeader("Accept-Language");
                }
                if(accLangs != null) {
                    StringTokenizer toks = new StringTokenizer(accLangs, ",");
                    while(toks.hasMoreTokens()) {
                        // Loop through all languages and cut off trailing extensions
                        String current = toks.nextToken().trim();
                        if(current.indexOf("-") > -1) {
                            current = current.substring(0, current.indexOf("-"));
                        }
                        if(current.indexOf(";") > -1) {
                            current = current.substring(0, current.indexOf(";"));
                        }
                        m_language.addElement(current);

                    }
                }
            }catch(UnsupportedOperationException e){
            }
        }
    }
    /**
     * Determines if the users is in the admin-group.
     *
     * @return <code>true</code> if the users current group is the admin-group; <code>false</code> otherwise.
     *
     * @exception CmsException if operation was not successful.
     */
    public boolean isAdmin()
        throws CmsException {
        return( m_rb.isAdmin(m_user, m_currentProject) );
    }
    /**
     * Determines if the users current group is the projectmanager-group.
     * <BR>
     * All projectmanagers can create new projects, or close their own projects.
     *
     * @return <code>true</code> if the users current group is the projectleader-group; <code>false</code> otherwise.
     *
     * @exception CmsException if operation was not successful.
     */
    public  boolean isProjectManager()
        throws CmsException {
        return( m_rb.isProjectManager(m_user, m_currentProject) );
    }
    /**
     * Sets the current group of the current user.
     *
     * @param groupname the name of the group to be set as current group.
     *
     * @exception CmsException if operation was not successful.
     */
    public void setCurrentGroup(String groupname)
        throws CmsException {

        // is the user in that group?
        if(m_rb.userInGroup(m_user, m_currentProject, m_user.getName(), groupname)) {
            // Yes - set it to the current Group.
            m_currentGroup = m_rb.readGroup(m_user, m_currentProject, groupname);
        } else {
            // No - throw exception.
            throw new CmsException("[" + this.getClass().getName() + "] " + groupname,
                CmsException.C_NO_ACCESS);
        }
    }
    /**
     * Sets the current project for the user.
     *
     * @param projectId the id of the project to be set as current project.
     * @exception CmsException if operation was not successful.
     */
    public CmsProject setCurrentProject(int projectId)
        throws CmsException  {
        CmsProject newProject = m_rb.readProject(m_user,
                                                   m_currentProject,
                                                   projectId);
        if( newProject != null ) {
            m_currentProject = newProject;
        }
        return( m_currentProject );
    }

    /**
     * Get the current mode for HTTP streaming.
     *
     * @return <code>true</code> if template classes are allowed to stream the
     *    results to the response output stream theirselves, <code>false</code> otherwise.
     */
    public boolean isStreaming() {
        return m_streaming;
    }

    /**
     * Set the current mode for HTTP streaming.<p>
     * Calling this method is only allowed, if the response output stream was
     * not used before. Otherwise the streaming mode must not be changed.
     *
     * @param b <code>true</code> if template classes are allowed to stream the
     *    results to the response's output stream theirselves, <code>false</code> otherwise.
     * @exception CmsException if the output stream was already used previously.
     */
    public void setStreaming(boolean b) throws CmsException {
        if((m_streaming != b) && getResponse().isOutputWritten()) {
            throw new CmsException("[CmsRequestContext] Cannot switch streaming mode, if output stream is used previously.", CmsException.C_STREAMING_ERROR);
        }
        m_streaming = b;
    }

    /**
     * Get the current mode for element cache.
     *
     * @return <code>true</code> if element cache is active, <code>false</code> otherwise.
     */
    public boolean isElementCacheEnabled() {
        return (m_elementCache != null);
    }

    /**
     * Get the CmsElementCache object. This is the starting point for the element cache area.
     * @return CmsElementCachee
     */
    public CmsElementCache getElementCache() {
        return m_elementCache;
    }

    /**
     * Get a Vector of all accepted languages for this request.
     * Languages are coded in international shortcuts like "en" or "de".
     * If the browser has sent special versions of languages (e.g. "de-ch" for Swiss-German)
     * these extensions will be cut off.
     * @return Vector of Strings with language codes or <code>null</code> if no request object is available.
     */
    public Vector getAcceptedLanguages() {
        return m_language;
    }

    /**
     * Returns the name of the current site root, e.g. /default/vfs
     *
     * @param resourcename
     * @return String The resourcename with its site root
     */
    public String getSiteRoot(String resourcename){
        if(resourcename.startsWith("///")){
            return resourcename.substring(2);
        } else if (resourcename.startsWith("//")){
            return C_DEFAULT_SITE+resourcename.substring(1);
        } else {
            return m_siteRoot+resourcename;
        }
    }

    /**
     * Returns the name of the current site, e.g. /default
     *
     * @return String The site name
     */
    public String getSiteName(){
        return C_DEFAULT_SITE;
    }

    /**
     * Sets the name of the current site root
     * of the virtual file system
     */
    public void setContextTo(String name){
        m_siteRoot = C_DEFAULT_SITE+name;
    }
}

⌨️ 快捷键说明

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