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

📄 cmsadminusers.java

📁 内容管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsAdminUsers.java,v $
* Date   : $Date: 2003/01/20 23:59:19 $
* Version: $Revision: 1.25 $
*
* 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.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsGroup;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsRequestContext;
import com.opencms.file.CmsUser;
import com.opencms.util.Utils;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Template class for displaying OpenCms workplace admin users screens.
 * <P>
 *
 * @author Mario Stanke
 * @version $Revision: 1.25 $ $Date: 2003/01/20 23:59:19 $
 * @see com.opencms.workplace.CmsXmlWpTemplateFile
 */

public class CmsAdminUsers extends CmsWorkplaceDefault implements I_CmsConstants {

    /**
     * change the groups of the user
     * <P>
     * the Vector newGroups holds all groups, which theUser will be in afterwards
     * the amount of database access is kept small with this funcion
     * @param cms CmsObject Object for accessing system resources.
     * @param theUser the user whose data will be changed
     * @param defaultGroupName String which holds the name of the default group theUser should get
     * @param newGroups Vector of Strings with the names of the new groups of theUser
     * @throws CmsException
     */

    private void changeGroups(CmsObject cms, CmsUser theUser, String defaultGroupName,
            Vector newGroups) throws CmsException {
        String username = (String)theUser.getName();
        Vector oldGroups = cms.getGroupsOfUser(username);
        Vector oldGroupnames = new Vector();
        if(defaultGroupName == null) {
            throw new CmsException("method 'changeGroups': default group set to null",
                    CmsException.C_NO_DEFAULT_GROUP);
        }
        theUser.setDefaultGroup(cms.readGroup(defaultGroupName));
        cms.writeUser(theUser); // update in the database
        theUser = (CmsUser)cms.readUser(username);
        if(oldGroups != null) {
            for(int z = 0;z < oldGroups.size();z++) {
                oldGroupnames.addElement(((CmsGroup)oldGroups.elementAt(z)).getName());
            }
            String oldDefaultGroup = theUser.getDefaultGroup().getName();
            oldGroupnames.removeElement(oldDefaultGroup);

            // delete the user from the groups which are not in newGroups
            for(int z = 0;z < oldGroupnames.size();z++) {
                String groupname = (String)oldGroupnames.elementAt(z);
                if(!newGroups.contains(groupname)) {
                    try {
                        cms.removeUserFromGroup(username, groupname);
                    }catch(CmsException e) {
                    // can happen when this group has been deleted _indirectly_ before
                    }
                }
            }
        }
        if(newGroups != null) {

            // now add the user to the new groups, which he not yet belongs to
            for(int z = 0;z < newGroups.size();z++) {
                String groupname = (String)newGroups.elementAt(z);
                if(!cms.userInGroup(username, groupname)) {
                    cms.addUserToGroup(username, groupname);
                }
            }
        }
        cms.writeUser(theUser); // update in the database
        theUser = (CmsUser)cms.readUser(username);
    }

    /**
     * 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(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() && C_DEBUG) {
            A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName() + "getting content of element "
                    + ((elementName == null) ? "<root>" : elementName));
            A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName() + "template file is: "
                    + templateFile);
            A_OpenCms.log(C_OPENCMS_DEBUG, this.getClassName() + "selected template section is: "
                    + ((templateSelector == null) ? "<default>" : templateSelector));
        }
        I_CmsSession session = cms.getRequestContext().getSession(true);
        CmsRequestContext reqCont = cms.getRequestContext();
        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
        boolean userYetChanged = true;
        boolean userYetEstablished = true;

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

                // change data of selected user
                perspective = "changeuser";
                userYetChanged = false;
            }else {
                if(reqCont.getRequest().getParameter("DELETE") != null) {

                    // delete the selected user
                    perspective = "deleteuser";
                }else {
                    if(reqCont.getRequest().getParameter("NEW") != null) {

                        // establish a new user
                        perspective = "newuser";
                        userYetEstablished = false;
                    }
                }
            }
        }
        if(perspective == null) {

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

            // first the common part of the two actions:
            // read the common parameters like first name, description, ...
            String firstname, desc, street, pwd, pwd2, user, userLastname, town, zipcode,
                    email, defaultGroup;
            if(session.getValue("ERROR") == null) {
                firstname = (String)parameters.get("USERFIRSTNAME");
                desc = (String)parameters.get("USERDESC");
                street = (String)parameters.get("USERSTREET");
                pwd = (String)parameters.get("PWD");
                pwd2 = (String)parameters.get("PWD2");
                user = (String)parameters.get("USER");
                userLastname = (String)parameters.get("USERNAME");
                town = (String)parameters.get("TOWN");
                zipcode = (String)parameters.get("ZIP");
                email = (String)parameters.get("USEREMAIL");
                defaultGroup = (String)parameters.get("DEFAULTGROUP");
            }else {

                // an error has occurred before, retrieve the form data from the session
                firstname = (String)session.getValue("USERFIRSTNAME");
                desc = (String)session.getValue("USERDESC");
                street = (String)session.getValue("USERSTREET");
                pwd = (String)session.getValue("PWD");
                pwd2 = (String)session.getValue("PWD2");
                user = (String)session.getValue("USER");
                userLastname = (String)session.getValue("USERNAME");
                town = (String)session.getValue("TOWN");
                zipcode = (String)session.getValue("ZIP");
                email = (String)session.getValue("USEREMAIL");
                defaultGroup = (String)session.getValue("DEFAULTGROUP");
                session.removeValue("ERROR");
            }
            if(firstname == null) {
                firstname = "";
            }
            if(desc == null) {
                desc = "";
            }
            if(street == null) {
                street = "";
            }
            if(pwd == null) {
                pwd = "";
            }
            if(pwd2 == null) {
                pwd2 = "";
            }
            if(user == null) {
                user = "";
            }
            if(userLastname == null) {
                userLastname = "";
            }
            if(town == null) {
                town = "";
            }
            if(zipcode == null) {
                zipcode = "";
            }
            if(email == null) {
                email = "";
            }
            if(defaultGroup == null) {
                defaultGroup = "";
            }

            // vectors of Strings that hold the selected and not selected Groups
            Vector selectedGroups = (Vector)session.getValue("selectedGroups");
            Vector notSelectedGroups = (Vector)session.getValue("notSelectedGroups");
            if(perspective.equals("newuser")) {

                // input is the form for establishing new users
                templateSelector = "newuser";
                if(!userYetEstablished) {

                    // first time the form is visited
                    user = "";
                    selectedGroups = new Vector();
                    notSelectedGroups = new Vector();
                    selectedGroups.addElement(C_GROUP_USERS); // preselect Users
                    Vector groups = cms.getGroups();
                    for(int z = 0;z < groups.size();z++) {
                        String aName = (String)((CmsGroup)groups.elementAt(z)).getName();
                        if(!C_GROUP_USERS.equals(aName)) {
                            notSelectedGroups.addElement(aName);
                        }
                    }
                    session.putValue("selectedGroups", selectedGroups);
                    session.putValue("notSelectedGroups", notSelectedGroups);
                }
                if(reqCont.getRequest().getParameter("ADD") != null) {

                    // add a new group to selectedGroups
                    String groupname = (String)parameters.get("notselectgroup");
                    if(groupname != null) {
                        selectedGroups.addElement(groupname);
                        notSelectedGroups.removeElement(groupname);
                    }
                    session.putValue("selectedGroups", selectedGroups);
                    session.putValue("notSelectedGroups", notSelectedGroups);
                }else {
                    if(reqCont.getRequest().getParameter("REMOVE") != null) {

                        // delete a new group from selectedGroups
                        // and move it to notSelectedGroups
                        String groupname = (String)parameters.get("selectgroup");
                        if(groupname != null) {
                            notSelectedGroups.addElement(groupname);
                            selectedGroups.removeElement(groupname);
                            if(groupname.equals(defaultGroup)) {
                                defaultGroup = "";
                            }
                        }
                        session.putValue("selectedGroups", selectedGroups);
                        session.putValue("notSelectedGroups", notSelectedGroups);

⌨️ 快捷键说明

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