destinationwizardservlet.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 386 行 · 第 1/2 页

JAVA
386
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 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.//// 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///package org.opennms.web.admin.notification;import java.io.IOException;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.opennms.netmgt.config.DestinationPathFactory;import org.opennms.netmgt.config.destinationPaths.Escalate;import org.opennms.netmgt.config.destinationPaths.Path;import org.opennms.netmgt.config.destinationPaths.Target;import org.opennms.web.Util;/** * A servlet that handles the data comming in from the destination wizard jsps. *  * @author <A HREF="mailto:jason@opennms.org">Jason Johns </A> * @author <A HREF="http://www.opennms.org/">OpenNMS </A> */public class DestinationWizardServlet extends HttpServlet {    private String SOURCE_PAGE_PATHS = "destinationPaths.jsp";    private String SOURCE_PAGE_OUTLINE = "pathOutline.jsp";    private String SOURCE_PAGE_TARGETS = "chooseTargets.jsp";    private String SOURCE_PAGE_INTERVALS = "groupIntervals.jsp";    private String SOURCE_PAGE_COMMANDS = "chooseCommands.jsp";    private String SOURCE_PAGE_NAME = "pathName.jsp";    private String SOURCE_PAGE_ESCALATE_REMOVE = "removeEscalation.jsp";    private String SOURCE_PAGE_ESCALATE_ADD = "addEscalation.jsp";    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {        String sourcePage = request.getParameter("sourcePage");        HttpSession user = request.getSession(true);        StringBuffer redirectString = new StringBuffer();        if (sourcePage.equals(SOURCE_PAGE_PATHS)) {            String action = request.getParameter("userAction");            if (action.equals("edit")) {                // get the path that was choosen in the select                try {                    Path oldPath = DestinationPathFactory.getInstance().getPath(request.getParameter("paths"));                    user.setAttribute("oldPath", oldPath);                    user.setAttribute("oldName", oldPath.getName());                    // copy the old path into the new path                    Path newPath = copyPath(oldPath);                    user.setAttribute("newPath", newPath);                    redirectString.append(SOURCE_PAGE_OUTLINE);                } catch (Exception e) {                    throw new ServletException("Couldn't get path to edit.", e);                }            } else if (action.equals("delete")) {                try {                    DestinationPathFactory.getInstance().removePath(request.getParameter("paths"));                    redirectString.append(SOURCE_PAGE_PATHS);                } catch (Exception e) {                    throw new ServletException("Couldn't save/reload destination path configuration file.", e);                }            } else if (action.equals("new")) {                Path newPath = new Path();                user.setAttribute("newPath", newPath);                redirectString.append(SOURCE_PAGE_OUTLINE);            }        } else if (sourcePage.equals(SOURCE_PAGE_OUTLINE)) {            String action = request.getParameter("userAction");            Path path = (Path) user.getAttribute("newPath");            // load all chanagable values from the outline page into the editing            // path            saveOutlineForm(path, request);            if (action.equals("add")) {                int index = Integer.parseInt(request.getParameter("index"));                Escalate newEscalate = new Escalate();                path.addEscalate(index, newEscalate);                Map requestParams = new HashMap();                requestParams.put("targetIndex", request.getParameter("index"));                redirectString.append(SOURCE_PAGE_TARGETS).append(makeQueryString(requestParams));            } else if (action.equals("remove")) {                int index = Integer.parseInt(request.getParameter("index"));                removeEscalation(path, index);                redirectString.append(SOURCE_PAGE_OUTLINE);            } else if (action.equals("edit")) {                Map requestParams = new HashMap();                requestParams.put("targetIndex", request.getParameter("index"));                redirectString.append(SOURCE_PAGE_TARGETS).append(makeQueryString(requestParams));            } else if (action.equals("finish")) {                String oldName = (String) user.getAttribute("oldName");                path.setName(request.getParameter("name"));                path.setInitialDelay(request.getParameter("initialDelay"));                try {                    if (oldName != null && !oldName.equals(path.getName())) {                        // replacing a path with a new name                        DestinationPathFactory.getInstance().replacePath(oldName, path);                    } else {                        DestinationPathFactory.getInstance().addPath(path);                    }                } catch (Exception e) {                    throw new ServletException("Couldn't save/reload destination path configuration file.", e);                }                // Must clear out this attribute for later edits                user.setAttribute("oldName", null);                redirectString.append(SOURCE_PAGE_PATHS);            } else if (action.equals("cancel")) {                redirectString.append(SOURCE_PAGE_PATHS);            }        } else if (sourcePage.equals(SOURCE_PAGE_TARGETS)) {            // compare the list of targets choosen to the existing targets,            // replacing            // and creating new targets as necessary            String userTargets[] = request.getParameterValues("users");            String groupTargets[] = request.getParameterValues("groups");            String emailTargets[] = request.getParameterValues("emails");            Path newPath = (Path) user.getAttribute("newPath");            int index = Integer.parseInt(request.getParameter("targetIndex"));            Target[] existingTargets = null;            try {                existingTargets = DestinationPathFactory.getInstance().getTargetList(index, newPath);            } catch (Exception e) {                throw new ServletException("Unable to get targets for path " + newPath.getName(), e);            }            // remove all the targets from the path or escalation            if (index == -1) {                newPath.clearTarget();            } else {                newPath.getEscalate(index).clearTarget();            }            // reload the new targets into the path or escalation            if (userTargets != null) {                for (int i = 0; i < userTargets.length; i++) {                    Target target = new Target();                    target.setName(userTargets[i]);                    // see if this target already exists                    for (int j = 0; j < existingTargets.length; j++) {                        if (userTargets[i].equals(existingTargets[j].getName())) {                            target = existingTargets[j];

⌨️ 快捷键说明

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