cmswpmain.java

来自「java 编写的程序」· Java 代码 · 共 342 行 · 第 1/2 页

JAVA
342
字号
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsWpMain.java,v $
* Date   : $Date: 2001/10/05 07:33:07 $
* Version: $Revision: 1.41 $
*
* 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.workplace;

import com.opencms.file.*;
import com.opencms.core.*;
import com.opencms.util.*;
import com.opencms.template.*;
import java.util.*;
import javax.servlet.http.*;

/**
 * Template class for displaying OpenCms workplace main screen.
 * <P>
 * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
 *
 * @author Alexander Lucas
 * @author Michael Emmerich
 * @version $Revision: 1.41 $ $Date: 2001/10/05 07:33:07 $
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 */

public class CmsWpMain extends CmsWorkplaceDefault {

    private Vector m_viewNames = null;

    private Vector m_viewLinks = null;

    /**
     * Gets the content of a defined section in a given template file and its subtemplates
     * with the given parameters.
     *
     * @see getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters)
     * @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.
     */

    public byte[] getContent(CmsObject cms, String templateFile, String elementName, Hashtable parameters,
            String templateSelector) throws CmsException {
        if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
            A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlTemplate] getting content of element "
                    + ((elementName == null) ? "<root>" : elementName));
            A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlTemplate] template file is: " + templateFile);
            A_OpenCms.log(C_OPENCMS_DEBUG, "[CmsXmlTemplate] selected template section is: "
                    + ((templateSelector == null) ? "<default>" : templateSelector));
        }
        I_CmsSession session = cms.getRequestContext().getSession(true);
        CmsRequestContext reqCont = cms.getRequestContext();
        String newGroup = (String)parameters.get("group");
        String newProject = (String)parameters.get("project");
        String newView = (String)parameters.get(C_PARA_VIEW);
        CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile,
                elementName, parameters, templateSelector);

        // Check if the user requested a group change
        if(newGroup != null && !("".equals(newGroup))) {
            if(!(newGroup.equals(reqCont.currentGroup().getName()))) {
                reqCont.setCurrentGroup(newGroup);
            }
        }

        // Check if the user requested a project change
        if(newProject != null && !("".equals(newProject))) {
            if(!(Integer.parseInt(newProject) == reqCont.currentProject().getId())) {
                reqCont.setCurrentProject(Integer.parseInt(newProject));
            }
        }

        // Check if the user requested a new view
        if(newView != null && !("".equals(newView))) {
            session = cms.getRequestContext().getSession(true);
            session.putValue(C_PARA_VIEW, newView);
        }

        // set the publishProject Button to enable if user has the right to publish the project
        if (templateFile.equalsIgnoreCase(xmlTemplateDocument.C_TEMPLATEPATH+"head")){
            if((cms.isAdmin() || cms.isManagerOfProject())
                            && (!reqCont.currentProject().equals(cms.onlineProject()))){
                xmlTemplateDocument.setData("publish", xmlTemplateDocument.getProcessedDataValue("PUBLISH_ENABLED", this));
            }else{
                xmlTemplateDocument.setData("publish", xmlTemplateDocument.getProcessedDataValue("PUBLISH_DISABLED", this));
            }
        }

        // set the sync button to enabled if no entries for synchronisation in registry
        if (templateFile.equalsIgnoreCase(xmlTemplateDocument.C_TEMPLATEPATH+"head")){
            String syncpath = null;
            syncpath = cms.getRegistry().getSystemValue(CmsSyncFolder.C_SYNCHRONISATION_PROJECT);
            if(syncpath == null) {
                xmlTemplateDocument.setData(CmsSyncFolder.C_SYNC_BUTTON, xmlTemplateDocument.getProcessedDataValue(CmsSyncFolder.C_SYNC_BUTTON_DISABLED, this));
            } else {
                xmlTemplateDocument.setData(CmsSyncFolder.C_SYNC_BUTTON, xmlTemplateDocument.getProcessedDataValue(CmsSyncFolder.C_SYNC_BUTTON_ENABLED, this));
            }
        }
        // send message, if this is the foot
        if (templateFile.equalsIgnoreCase(xmlTemplateDocument.C_TEMPLATEPATH+"foot")){
            String message = (String)cms.getRequestContext().getSession(true).getValue(I_CmsConstants.C_SESSION_BROADCASTMESSAGE);
            if(message != null) {
                cms.getRequestContext().getSession(true).removeValue(I_CmsConstants.C_SESSION_BROADCASTMESSAGE);
                xmlTemplateDocument.setData("message", "alert(unescape('BROADCASTMESSAGE: " + Encoder.escape(message) + "'));");
            }
        }

        // Now load the template file and start the processing
        return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
    }

    /**
     * Gets all groups of the currently logged in user.
     * <P>
     * The given vectors <code>names</code> and <code>values</code> will
     * be filled with the appropriate information to be used for building
     * a select box.
     * <P>
     * Both <code>names</code> and <code>values</code> will contain
     * the group names after returning from this method.
     * <P>
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param lang reference to the currently valid language file
     * @param names Vector to be filled with the appropriate values in this method.
     * @param values Vector to be filled with the appropriate values in this method.
     * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
     * @return Index representing the user's current group in the vectors.
     * @exception CmsException
     */

    public Integer getGroups(CmsObject cms, CmsXmlLanguageFile lang, Vector names, Vector values,
            Hashtable parameters) throws CmsException {

        // Get a vector of all of the user's groups by asking the request context
        CmsRequestContext reqCont = cms.getRequestContext();
        CmsGroup currentGroup = reqCont.currentGroup();
        Vector allGroups = cms.getGroupsOfUser(reqCont.currentUser().getName());

        // Now loop through all groups and fill the result vectors
        int numGroups = allGroups.size();
        int currentGroupNum = 0;
        for(int i = 0;i < numGroups;i++) {
            CmsGroup loopGroup = (CmsGroup)allGroups.elementAt(i);
            String loopGroupName = loopGroup.getName();

⌨️ 快捷键说明

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