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

📄 cmsadmingroups.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminGroups.java,v $
* Date   : $Date: 2005/06/07 16:25:40 $
* Version: $Revision: 1.5 $
*
* 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 org.opencms.file.CmsGroup;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsRequestContext;
import org.opencms.file.CmsUser;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;

import com.opencms.core.I_CmsSession;
import com.opencms.legacy.CmsLegacyException;
import com.opencms.legacy.CmsXmlTemplateLoader;

import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

/**
 * Template class for displaying OpenCms workplace admin group screens.
 * <P>
 *
 * @author Mario Stanke
 * @version $Revision: 1.5 $ $Date: 2005/06/07 16:25:40 $
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 * 
 * @deprecated Will not be supported past the OpenCms 6 release.
 */

public class CmsAdminGroups extends CmsWorkplaceDefault {


    /**
     * String constant which is submitted in the select box 'supergroup'
     */

    // Could cause a problem if a real groupname happens to be "none_selected"
    final static String C_NO_SUPERGROUP_SELECTED = "none_selected";

    /**
     * Gets the content of a defined section in a given template file and its subtemplates
     * with the given parameters.
     *
     * @see #getContent(CmsObject, String, String, Hashtable, String)
     * @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(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
            CmsLog.getLog(this).debug("Getting content of element " + ((elementName == null) ? "<root>" : elementName));
            CmsLog.getLog(this).debug("Template file is: " + templateFile);
            CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector == null) ? "<default>" : templateSelector));
        }
        I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
        CmsRequestContext reqCont = cms.getRequestContext();
        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        boolean groupYetChanged = true;
        boolean groupYetEstablished = true;

        // find out which template (=perspective) should be used
        String perspective = (String)parameters.get("perspective");
        if(perspective != null && perspective.equals("group")) {
            session.removeValue("ERROR");
            if(CmsXmlTemplateLoader.getRequest(reqCont).getParameter("CHANGE") != null) {

                // change data of selected user
                perspective = "changegroup";
                groupYetChanged = false;
            }
            else {
                if(parameters.get("DELETE") != null) {

                    // delete the selected user
                    perspective = "deletegroup";
                }
                else {
                    if(parameters.get("NEW") != null) {

                        // establish new group
                        perspective = "newgroup";
                        groupYetEstablished = false;
                    }
                }
            }
        }
        if(perspective == null) {

            // display the first template, which lets you chose the action
            perspective = new String("group");
        }
        if(perspective.equals("newgroup") || perspective.equals("changegroup")) {

            // first the common part of the two actions:
            // read the parameters like group name, description, ...
            String groupname, description, supergroup;
            boolean projectManager, projectCoWorker, role;
            if(session.getValue("ERROR") == null) {
                groupname = (String)parameters.get("GROUPNAME");
                description = (String)parameters.get("GROUPDESC");
                supergroup = (String)parameters.get("SUPERGROUP");
                projectManager = (parameters.get("PROJECTMANAGER") != null);
                projectCoWorker = (parameters.get("PROJECTCOWORKER") != null);
                role = (parameters.get("ROLE") != null);
            }
            else {

                // an error has occurred before, retrieve the form data from the session
                groupname = (String)session.getValue("GROUPNAME");
                description = (String)session.getValue("GROUPDESC");
                supergroup = (String)session.getValue("SUPERGROUP");
                projectManager = (session.getValue("PROJECTMANAGER") != null);
                projectCoWorker = (session.getValue("PROJECTCOWORKER") != null);
                role = (session.getValue("ROLE") != null);

                // remove the data from parameters
                parameters.remove("ADD");
                parameters.remove("REMOVE");
                parameters.remove("OK");
                session.removeValue("ERROR");
            }
            if(groupname == null) {
                groupname = "";
            }
            if(description == null) {
                description = "";
            }
            if(supergroup == null) {
                supergroup = "";
            }
            session.putValue("SUPERGROUP", supergroup);

            // vectors of Strings that hold the selected and not selected Users
            Vector selectedUsers = (Vector)session.getValue("selectedUsers");
            Vector notSelectedUsers = (Vector)session.getValue("notSelectedUsers");
            if(perspective.equals("newgroup")) {

                // input is the form for establishing a new group
                templateSelector = "newgroup";
                if(!groupYetEstablished) {

                    // first time the form is visited
                    groupname = "";
                    selectedUsers = new Vector();
                    notSelectedUsers = new Vector();
                    List users = cms.getUsers();
                    for(int z = 0;z < users.size();z++) {
                        notSelectedUsers.addElement(((CmsUser)users.get(z)).getName());
                    }
                    session.putValue("selectedUsers", selectedUsers);
                    session.putValue("notSelectedUsers", notSelectedUsers);
                }
                if(parameters.get("ADD") != null) {

                    // add a new group to selectedGroups
                    String username = (String)parameters.get("NOTSELECTEDUSERS");
                    if(username != null) {
                        selectedUsers.addElement(username);
                        notSelectedUsers.removeElement(username);
                    }
                    session.putValue("selectedUsers", selectedUsers);
                    session.putValue("notSelectedUsers", notSelectedUsers);
                }
                else {
                    if(parameters.get("REMOVE") != null) {

                        // delete a new group from selectedGroups
                        // and move it to notSelectedGroups
                        String username = (String)parameters.get("SELECTEDUSERS");
                        if(username != null) {
                            notSelectedUsers.addElement(username);
                            selectedUsers.removeElement(username);
                        }
                        session.putValue("selectedUsers", selectedUsers);
                        session.putValue("notSelectedUsers", notSelectedUsers);
                    }
                    else {
                        if(parameters.get("OK") != null) {

                            // form submitted, try to establish new group
                            try {
                                if(groupname == null || groupname.equals("")) {
                                    throw new CmsLegacyException("no groupname", CmsLegacyException.C_NO_GROUP);
                                }
                                if(C_NO_SUPERGROUP_SELECTED.equals(supergroup)) {
                                    supergroup = ""; // no supergroup
                                }
                                CmsGroup newGroup = cms.createGroup(groupname, description, 0, supergroup);
                                newGroup.setProjectManager(projectManager);
                                newGroup.setProjectCoWorker(projectCoWorker);
                                newGroup.setRole(role);
                                cms.writeGroup(newGroup);
                                for(int z = 0;z < selectedUsers.size();z++) {
                                    cms.addUserToGroup((String)selectedUsers.elementAt(z), groupname);
                                }
                                session.removeValue("selectedUsers");
                                session.removeValue("notSelectedUsers");
                                session.removeValue("SUPERGROUP");
                                session.removeValue("PROJECTMANAGER");
                                session.removeValue("PROJECTCOWORKER");
                                session.removeValue("ROLE");
                                session.removeValue("ERROR");
                                templateSelector = ""; //successful
                            }
                            catch(CmsException e) {

                                // save the form data in the session, so it can be displayed again later
                                session.putValue("ERROR", new String("yes")); // remeber that an error has occurred
                                session.putValue("GROUPNAME", groupname);
                                session.putValue("GROUPDESC", description);
                                session.putValue("SUPERGROUP", supergroup);
                                if(projectManager) {
                                    session.putValue("PROJECTMANAGER", "yes");
                                }
                                else {
                                    session.removeValue("PROJECTMANAGER");
                                }
                                if(projectCoWorker) {
                                    session.putValue("PROJECTCOWORKER", "yes");
                                }
                                else {
                                    session.removeValue("PROJECTCOWORKER");
                                }
                                if(role) {
                                    session.putValue("ROLE", "yes");
                                }
                                else {
                                    session.removeValue("ROLE");
                                }
                                if ((e instanceof CmsLegacyException) && (((CmsLegacyException)e).getType() == CmsLegacyException.C_NO_GROUP) && e.getMessage().equals("no groupname")) {
                                    templateSelector = "errordatamissing1";
                                }
                                else {
                                    throw e; // hand the exception down
                                }
                            }
                        }
                    }
                }
            }
            else {

                // input is the form for changing the group data
                templateSelector = "changegroup";
                if(!groupYetChanged) {

                    // form visited for the first time, not yet changed

                    // read the data from the group object
                    CmsGroup theGroup = cms.readGroup(groupname);
                    if(theGroup == null) {
                        throw new CmsLegacyException("user does not exist");
                    }
                    projectManager = theGroup.getProjectManager();
                    projectCoWorker = theGroup.getProjectCoWorker();
                    role = theGroup.getRole();
                    description = theGroup.getDescription();
                    CmsGroup parent = cms.getParent(groupname);
                    if(parent != null) {
                        supergroup = cms.getParent(groupname).getName();
                    }
                    else {
                        supergroup = "";
                    }
                    List users = cms.getUsersOfGroup(groupname);
                    if(users != null) {
                        selectedUsers = new Vector();
                        for(int z = 0;z < users.size();z++) {
                            selectedUsers.addElement(((CmsUser)users.get(z)).getName());
                        }
                    }
                    users = cms.getUsers();
                    if(users != null) {
                        notSelectedUsers = new Vector();
                        for(int z = 0;z < users.size();z++) {
                            String name = ((CmsUser)users.get(z)).getName();
                            if(!selectedUsers.contains(name)) {
                                notSelectedUsers.addElement(name);
                            }
                        }
                    }
                }
                else {
                    if(parameters.get("ADD") != null) {

⌨️ 快捷键说明

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