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

📄 usermanager.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2005 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program 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 General Public License for more details.                                                            //// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//    // For more information contact: //   OpenNMS Licensing       <license@opennms.org>//   http://www.opennms.org///   http://www.opennms.com///// Tab Size = 8package org.opennms.netmgt.config;import java.io.FileNotFoundException;import java.io.IOException;import java.io.Reader;import java.io.StringWriter;import java.security.MessageDigest;import java.security.NoSuchAlgorithmException;import java.util.ArrayList;import java.util.Calendar;import java.util.Collection;import java.util.Date;import java.util.Enumeration;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.exolab.castor.xml.MarshalException;import org.exolab.castor.xml.Marshaller;import org.exolab.castor.xml.Unmarshaller;import org.exolab.castor.xml.ValidationException;import org.opennms.netmgt.EventConstants;import org.opennms.netmgt.config.users.Contact;import org.opennms.netmgt.config.users.DutySchedule;import org.opennms.netmgt.config.users.Header;import org.opennms.netmgt.config.users.User;import org.opennms.netmgt.config.users.Userinfo;import org.opennms.netmgt.config.users.Users;/** * @author david hustace <david@opennms.org> */public abstract class UserManager {    protected GroupManager m_groupManager;    /**     * A mapping of user ids to the User objects     */    protected HashMap m_users;    /**     * The duty schedules for each user     */    protected HashMap m_dutySchedules;    private Header oldHeader;    protected UserManager(GroupManager groupManager) {        m_groupManager = groupManager;    }    /**     * @param reader     * @throws MarshalException     * @throws ValidationException     */    public void parseXML(Reader reader) throws MarshalException, ValidationException {        Userinfo userinfo = (Userinfo) Unmarshaller.unmarshal(Userinfo.class, reader);        Users users = userinfo.getUsers();        oldHeader = userinfo.getHeader();        Collection usersList = users.getUserCollection();        m_users = new HashMap();            Iterator i = usersList.iterator();        while (i.hasNext()) {            User curUser = (User) i.next();            m_users.put(curUser.getUserId(), curUser);        }            buildDutySchedules(m_users);    }    /**     * Adds a new user and overwrites the "users.xml"     */    public synchronized void saveUser(String name, User details) throws Exception {        if (name == null || details == null) {            throw new Exception("UserFactory:saveUser  null");        } else {            m_users.put(name, details);        }            saveCurrent();    }    /**     * Builds a mapping between user ids and duty schedules. These are used by     * Notifd when determining to send a notice to a given user. This helps     * speed up the decision process.     *      * @param users     *            the map of users parsed from the xml config file     */    private void buildDutySchedules(Map users) {        m_dutySchedules = new HashMap();        Iterator i = users.keySet().iterator();            while (i.hasNext()) {            String key = (String) i.next();            User curUser = (User) users.get(key);                if (curUser.getDutyScheduleCount() > 0) {                List dutyList = new ArrayList();                Enumeration duties = curUser.enumerateDutySchedule();                    while (duties.hasMoreElements()) {                    dutyList.add(new DutySchedule((String) duties.nextElement()));                }                    m_dutySchedules.put(key, dutyList);            }        }    }    /**     * Determines if a user is on duty at a given time. If a user has no duty     * schedules listed in the config file, that user is assumed to always be on     * duty.     *      * @param user     *            the user id     * @param time     *            the time to check for a duty schedule     * @return boolean, true if the user is on duty, false otherwise.     */    public boolean isUserOnDuty(String user, Calendar time) throws IOException, MarshalException, ValidationException {            update();            // if the user has no duty schedules then he is on duty        if (!m_dutySchedules.containsKey(user))            return true;            boolean result = false;        List dutySchedules = (List) m_dutySchedules.get(user);            for (int i = 0; i < dutySchedules.size(); i++) {            DutySchedule curSchedule = (DutySchedule) dutySchedules.get(i);                result = curSchedule.isInSchedule(time);                // don't continue if the time is in this schedule            if (result)                break;        }            return result;    }    /**     * Return a <code>Map</code> of usernames to user instances.     */    public Map getUsers() throws IOException, MarshalException, ValidationException {            update();            return m_users;    }    /**     * Returns a boolean indicating if the user name appears in the xml file     *      * @return true if the user exists in the xml file, false otherwise     */    public boolean hasUser(String userName) throws IOException, MarshalException, ValidationException {            update();            return m_users.containsKey(userName);    }    /**     */    public List getUserNames() throws IOException, MarshalException, ValidationException {            update();            List userNames = new ArrayList();            Iterator i = m_users.keySet().iterator();            while (i.hasNext()) {            userNames.add((String) i.next());        }            return userNames;    }    /**     * Get a user by name     *      * @param name     *            the name of the user to return     * @return the user specified by name     */    public User getUser(String name) throws IOException, MarshalException, ValidationException {            update();            return (User) m_users.get(name);    }    /**     * Get the contact info given a command string     *      * @param userID     *            the name of the user     * @param command     *            the command to look up the contact info for     * @return the contact information     */    public String getContactInfo(String userID, String command) throws IOException, MarshalException, ValidationException {        update();            User user = (User) m_users.get(userID);        if (user == null)            return "";        String value = "";        Enumeration contacts = user.enumerateContact();        while (contacts != null && contacts.hasMoreElements()) {            Contact contact = (Contact) contacts.nextElement();            if (contact != null) {                if (contact.getType().equals(command)) {                    value = contact.getInfo();                    break;                }            }        }        return value;    }    /**     * Get a email by name     *      * @param userid     *            the userid of the user to return     * @return String the email specified by name     */    public String getEmail(String userid) throws IOException, MarshalException, ValidationException {            update();            User user = (User) m_users.get(userid);        if (user == null)            return "";        String value = "";        Enumeration contacts = user.enumerateContact();        while (contacts != null && contacts.hasMoreElements()) {            Contact contact = (Contact) contacts.nextElement();            if (contact != null) {                if (contact.getType().equals("email")) {                    value = contact.getInfo();                    break;                }            }        }        return value;    }    /**     * Get a pager email by name     *      * @param userid     *            the userid of the user to return     * @return String the pager email     */    public String getPagerEmail(String userid) throws IOException, MarshalException, ValidationException {            update();            User user = (User) m_users.get(userid);        if (user == null)            return "";        String value = "";        Enumeration contacts = user.enumerateContact();        while (contacts != null && contacts.hasMoreElements()) {            Contact contact = (Contact) contacts.nextElement();            if (contact != null) {                if (contact.getType().equals("pagerEmail")) {                    value = contact.getInfo();                    break;                }            }        }        return value;    }    /**     * Get an XMPP address by name     *      * @param userid     *            the userid of the user to return     * @return String the XMPP address     */    public String getXMPPAddress(String userid) throws IOException, MarshalException, ValidationException {        update();                User user = (User) m_users.get(userid);        if (user == null)            return "";        String value = "";        Enumeration contacts = user.enumerateContact();

⌨️ 快捷键说明

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