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

📄 cmsworkplacedefault.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @param templateFile Filename of the template file.
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     */
    public CmsXmlTemplateFile getOwnTemplateFile(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {
        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        return xmlTemplateDocument;
    }
    
    /**
     * Checks if the current user is <strong>administrator</strong>.
     * <P>
     * This method is used by workplace icons to decide whether the icon should
     * be activated or not. Icons will use this method if the attribute <code>method="isAdministrator"</code>
     * is defined in the <code>&lt;ICON&gt;</code> tag.
     *
     * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
     * @param lang reference to the currently valid language file <em>(not used here)</em>.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return <code>true</code> if the current user is in the Administrators Group, <code>false</code> otherwise.
     * @throws CmsException if there were errors while accessing project data.
     */
    public Boolean isAdmin(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        CmsRequestContext reqCont = cms.getRequestContext();
        return new Boolean(reqCont.isAdmin());
    }

    /**
     * Same as above, only that this returns always 'false'.
     * Can be used to quickly deactivate unwanted icons on the workplace even
     * for then admin by just adding "False" to isAdmin call in file property.
     */
    public Boolean isAdminFalse(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        return new Boolean(false);
    }
    
    /**
     * Checks if the current user is the administrator <strong>Admin</strong>.
     * <P>
     * This method is used by workplace icons to decide whether the icon should
     * be activated or not. 
     * 
     * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
     * @param lang reference to the currently valid language file <em>(not used here)</em>.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return <code>true</code> if the current user is the user Admin, <code>false</code> otherwise.
     * @throws CmsException if there were errors while accessing project data.
     */
    public Boolean isTheAdminUser(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        CmsRequestContext reqCont = cms.getRequestContext();
        if(reqCont.isAdmin()){
            return new Boolean(reqCont.currentUser().getName().equals(C_USER_ADMIN));
        }else{
            return new Boolean(false);
        }
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */
    public boolean isCacheable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }

    /**
     * gets the caching information from the current template class.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public CmsCacheDirectives getCacheDirectives(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return new CmsCacheDirectives(false);
    }

    /**
     * Indicates if the current template class is able to stream it's results
     * directly to the response oputput stream.
     * <P>
     * Classes must not set this feature, if they might throw special
     * exception that cause HTTP errors (e.g. 404/Not Found), or if they
     * might send HTTP redirects.
     * <p>
     * If a class sets this feature, it has to check the
     * isStreaming() property of the RequestContext. If this is set
     * to <code>true</code> the results must be streamed directly
     * to the output stream. If it is <code>false</code> the results
     * must not be streamed.
     * <P>
     * Complex classes that are able top include other subtemplates
     * have to check the streaming ability of their subclasses here!
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if this class may stream it's results, <EM>false</EM> otherwise.
     */
    public boolean isStreamable(CmsObject cms, String templateFile, String elementName, Hashtable parameters, String templateSelector) {
        return false;
    }

    /**
     * Checks if the current project is <STRONG>not</STRONG> the "Online" project.
     * <P>
     * This method is used by workplace icons to decide whether the icon should
     * be activated or not. Icons will use this method if the attribute <code>method="isNotOnlineProject"</code>
     * is defined in the <code>&lt;ICON&gt;</code> tag.
     *
     * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
     * @param lang reference to the currently valid language file <em>(not used here)</em>.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return <code>true</code> if the current project is the online project, <code>false</code> otherwise.
     * @throws CmsException if there were errors while accessing project data.
     */
    public Boolean isNotOnlineProject(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        CmsRequestContext reqCont = cms.getRequestContext();
        return new Boolean(!reqCont.currentProject().isOnlineProject());
    }

    /**
     * Checks if the current project is the "Online" project.
     * <P>
     * This method is used by workplace icons to decide whether the icon should
     * be activated or not. Icons will use this method if the attribute <code>method="isOnlineProject"</code>
     * is defined in the <code>&lt;ICON&gt;</code> tag.
     *
     * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
     * @param lang reference to the currently valid language file <em>(not used here)</em>.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return <code>true</code> if the current project is the online project, <code>false</code> otherwise.
     * @throws CmsException if there were errors while accessing project data.
     */
    public Boolean isOnlineProject(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        CmsRequestContext reqCont = cms.getRequestContext();
        return new Boolean(reqCont.currentProject().isOnlineProject());
    }

    /**
     * Checks if the current user is <STRONG>Project manager</STRONG>.
     * <P>
     * This method is used by workplace icons to decide whether the icon should
     * be activated or not. Icons will use this method if the attribute <code>method="isProjectManager"</code>
     * is defined in the <code>&lt;ICON&gt;</code> tag.
     *
     * @param cms CmsObject Object for accessing system resources <em>(not used here)</em>.
     * @param lang reference to the currently valid language file <em>(not used here)</em>.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return <code>true</code> if the current project is the online project, <code>false</code> otherwise.
     * @throws CmsException if there were errors while accessing project data.
     */
    public Boolean isProjectManager(CmsObject cms, CmsXmlLanguageFile lang, Hashtable parameters) throws CmsException {
        CmsRequestContext reqCont = cms.getRequestContext();
        return new Boolean((reqCont.isAdmin() || reqCont.isProjectManager()));
    }

    /**
     * User method to generate an URI for the system resources folder.<p>
     * 
     * All pictures and style sheets should reside in the docroot of the webserver for
     * performance reasons. This folder can be mounted into the OpenCms system to
     * make it accessible for the OpenCms explorer.<p>
     * 
     * The path to the docroot can be set in the workplace ini.<p>
     * 
     * In any workplace template file, this method can be invoked by
     * <code>&lt;METHOD name="resourcesUri"&gt;<em>PictureName</em>&lt;/METHOD&gt;</code>.<p>
     * 
     * <b>Warning:</b> Using this method, only workplace resources, usually residing
     * in the <code>/system/workplace/resources</code> folder, can be accessed. 
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XML document <em>(not used here)</em>.
     * @param userObj Hashtable with parameters <em>(not used here)</em>.
     * @return String with the resources URI
     * @throws CmsException
     */
    public Object resourcesUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
        if(m_resourcesUri == null) {
            CmsXmlWpConfigFile configFile = new CmsXmlWpConfigFile(cms);
            m_resourcesUri = configFile.getWpPicturePath();
        }
        if (tagcontent == null) return m_resourcesUri;
        return m_resourcesUri + tagcontent;
    }
    
    /**
     * User method to generate an URI for the system scripts folder.<p>
     * 
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XML document <em>(not used here)</em>.
     * @param userObj Hashtable with parameters <em>(not used here)</em>.
     * @return String with the scripts URI
     * @throws CmsException
     */
    public Object scriptsUri(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
        if(m_scriptsUri == null) {
            m_scriptsUri = cms.getRequestContext().getRequest().getServletUrl() + I_CmsWpConstants.C_VFS_PATH_SCRIPTS;
        }
        if (tagcontent == null) return m_scriptsUri;
        return m_scriptsUri + tagcontent;
    }

    /**
     * @deprecated use {@link #resourcesUri(CmsObject, String, A_CmsXmlContent, Object)} instead
     */
    public Object picsUrl(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
        return resourcesUri(cms, tagcontent, doc, userObj);
    }
    
    /**
     * Starts the processing of the given template file by calling the
     * <code>getProcessedTemplateContent()</code> method of the content defintition
     * of the corresponding content type.
     * <P>
     * Any exceptions thrown while processing the template will be caught,
     * printed and and thrown again.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param xmlTemplateDocument XML parsed document of the content type "XML template file" or
     * any derived content type.
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return Content of the template and all subtemplates.
     * @throws CmsException
     */
    protected byte[] startProcessing(CmsObject cms, CmsXmlTemplateFile xmlTemplateDocument, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {

        // checks if the access was with the correct port. If not it sends a not found error
        if( checkPort(cms) ) {
            String lasturl = getLastUrl(cms, parameters);
            // Since we are in the workplace, no browser caching is allowed here.
            // Set all caching information to "no-cache".
            // Don't bother about the internal caching here! Workplace users should be forced
            // to reload the workplace pages at every request.
            //HTTP 1.1
            cms.getRequestContext().getResponse().setHeader("Cache-Control", "no-cache");
            //HTTP 1.0
            cms.getRequestContext().getResponse().setHeader("Pragma", "no-cache");
            ((CmsXmlWpTemplateFile)xmlTemplateDocument).setData("lasturl", lasturl);
            return super.startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
        } else {
            throw new CmsException("No access to the workplace with this port", CmsException.C_NOT_FOUND);
        }
    }

    /**
     * Checks, if the request is running on the correct port. With the opencms.properties
     * the access to the workplace can be limitted to a user defined port. With this
     * feature a firewall can block all outside requests to this port with the result
     * the workplace is only available in the local net segment.
     * @param cms the CmsObject to check the port with.
     */
    protected boolean checkPort(CmsObject cms) {
        int portnumber = cms.getRequestContext().getRequest().getServerPort();
        int limitedPort = cms.getLimitedWorkplacePort();
        return ( (limitedPort == -1) ||
                 ( limitedPort == portnumber) );
    }

    /**
     * User method to get the name of the user.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document <em>(not used here)</em>.
     * @param userObj Hashtable with parameters <em>(not used here)</em>.
     * @return String with the pics URL.
     * @throws CmsException
     */
    public Object userName(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObj) throws CmsException {
        return Utils.getFullName(cms.getRequestContext().currentUser());
    }
}

⌨️ 快捷键说明

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