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

📄 cmsrequestcontext.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

    /**
     * Returns the file name translator this context was initialized with.<p>
     * 
     * The file name translator is used to translate filenames from uploaded files  
     * to valid OpenCms filenames. Example: <code>W黶te W鰎ter.doc --> Wueste_Woerter.doc</code>.<p>
     * 
     * @return the file name translator this context was initialized with
     */
    public CmsResourceTranslator getFileTranslator() {

        return m_fileTranslator;
    }

    /**
     * Gets the name of the parent folder of the requested file.<p>
     *
     * @return the name of the parent folder of the requested file
     */
    public String getFolderUri() {

        return getUri().substring(0, getUri().lastIndexOf("/") + 1);
    }

    /**
     * Returns the name of the requested locale within this context.<p>
     * 
     * @return the name of the locale
     */
    public Locale getLocale() {

        return m_locale;
    }

    /**
     * Returns the remote ip address.<p>
     * 
     * @return the renote ip addresss as string
     */
    public String getRemoteAddress() {

        return m_remoteAddr;
    }

    /**
     * Returns the current request time.<p>
     * 
     * @return the current request time
     */
    public long getRequestTime() {

        return m_requestTime;
    }

    /**
     * Adjusts the absolute resource root path for the current site.<p> 
     * 
     * The full root path of a resource is always available using
     * <code>{@link CmsResource#getRootPath()}</code>. From this name this method cuts 
     * of the current site root using 
     * <code>{@link CmsRequestContext#removeSiteRoot(String)}</code>.<p>
     * 
     * If the resource root path does not start with the current site root,
     * it is left untouched.<p>
     * 
     * @param resource the resource to get the adjusted site root path for
     * 
     * @return the absolute resource path adjusted for the current site
     * 
     * @see #removeSiteRoot(String)
     * @see CmsResource#getRootPath()
     * @see CmsObject#getSitePath(CmsResource)
     */
    public String getSitePath(CmsResource resource) {

        return removeSiteRoot(resource.getRootPath());
    }

    /**
     * Returns the current root directory in the virtual file system.<p>
     * 
     * @return the current root directory in the virtual file system
     */
    public String getSiteRoot() {

        return m_siteRoot;
    }

    /**
     * Returns the OpenCms VFS URI of the requested resource.<p>
     *
     * @return the OpenCms VFS URI of the requested resource
     */
    public String getUri() {

        return m_uri;
    }

    /**
     * Check if this request context will update the session.<p>
     * 
     * This is used mainly for CmsReports that continue to use the 
     * users context, even after the http request is already finished.<p>
     *
     * @return true if this request context will update the session, false otherwise
     */
    public boolean isUpdateSessionEnabled() {

        return m_updateSession;
    }

    /**
     * Removes the current site root prefix from the absolute path in the resource name,
     * that is adjusts the resource name for the current site root.<p> 
     * 
     * If the resource name does not start with the current site root,
     * it is left untouched.<p>
     * 
     * @param resourcename the resource name
     * 
     * @return the resource name adjusted for the current site root
     * 
     * @see #getSitePath(CmsResource)
     */
    public String removeSiteRoot(String resourcename) {

        String siteRoot = getAdjustedSiteRoot(m_siteRoot, resourcename);
        if ((siteRoot == m_siteRoot) && resourcename.startsWith(siteRoot)) {
            resourcename = resourcename.substring(siteRoot.length());
        }
        return resourcename;
    }

    /**
     * Restores the saved site root.<p>
     *
     * @throws RuntimeException in case there is no site root saved
     */
    public void restoreSiteRoot() throws RuntimeException {

        if (m_savedSiteRoot == null) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_EMPTY_SITEROOT_0));
        }
        m_siteRoot = m_savedSiteRoot;
        m_savedSiteRoot = null;
    }

    /**
     * Saves the current site root.<p>
     *
     * @throws RuntimeException in case there is already a site root saved
     */
    public void saveSiteRoot() throws RuntimeException {

        if (m_savedSiteRoot != null) {
            throw new CmsRuntimeException(Messages.get().container(Messages.ERR_NONEMPTY_SITEROOT_1, m_savedSiteRoot));
        }
        m_savedSiteRoot = m_siteRoot;
    }

    /**
     * Sets an attribute in the request context.<p>
     * 
     * @param key the attribute name
     * @param value the attribute value
     */
    public void setAttribute(String key, Object value) {

        if (m_attributeMap == null) {
            // Hashtable is still the most efficient form of a synchronized Map
            m_attributeMap = new Hashtable();
        }
        m_attributeMap.put(key, value);
    }

    /**
     * Sets the current project for the user.<p>
     *
     * @param project the project to be set as current project
     * @return the CmsProject instance
     */
    public CmsProject setCurrentProject(CmsProject project) {

        if (project != null) {
            m_currentProject = project;
        }
        return m_currentProject;
    }

    /**
     * Sets the current content encoding to be used in HTTP response.<p>
     * 
     * @param encoding the encoding
     */
    public void setEncoding(String encoding) {

        m_encoding = encoding;
    }

    /**
     * Sets the current request time.<p>
     * 
     * @param time the request time
     */
    public void setRequestTime(long time) {

        m_requestTime = time;
    }

    /**
     * Sets the current root directory in the virtual file system.<p>
     * 
     * @param root the name of the new root directory
     */
    public void setSiteRoot(String root) {

        // site roots must never end with a "/"
        if (root.endsWith("/")) {
            m_siteRoot = root.substring(0, root.length() - 1);
        } else {
            m_siteRoot = root;
        }
    }

    /**
     * Mark this request context to update the session or not.<p>
     *
     * @param value true if this request context will update the session, false otherwise
     */
    public void setUpdateSessionEnabled(boolean value) {

        m_updateSession = value;
    }

    /**
     * Set the requested resource OpenCms VFS URI, that is the value returned by {@link #getUri()}.<p>
     * 
     * Use this with caution! Many things (caches etc.) depend on this value.
     * If you change this value, better make sure that you change it only temporarily 
     * and reset it in a <code>try { // do something // } finaly { // reset URI // }</code> statement.<p>
     * 
     * @param value the value to set the Uri to, must be a complete OpenCms path name like /system/workplace/stlye.css
     */
    public void setUri(String value) {

        m_uri = value;
    }

    /**
     * Switches the user in the context, required after a login.<p>
     * 
     * @param user the new user to use
     * @param project the new users current project
     */
    protected void switchUser(CmsUser user, CmsProject project) {

        m_user = user;
        m_currentProject = project;
    }
}

⌨️ 快捷键说明

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