%@page language="java" contentType="text/html" session="true" import="java.util.*,org.opennms.netmgt.config.*,org.opennms.netmgt.config.poller.*,org.opennms.web.element.*,org.opennms.netmgt.EventConstants,org.opennms.netmgt.xml.event.Event,org.opennms.netmgt.utils.*,java.net.*,java.io.*" %>
<%!
//A singleton instance of a "Match-any" interface, which can be used for generic tests/removals etc.
private static org.opennms.netmgt.config.poller.Interface matchAnyInterface;
{
matchAnyInterface=new org.opennms.netmgt.config.poller.Interface();
matchAnyInterface.setAddress("match-any");
}
public void sendOutagesChangedEvent() throws ServletException {
Event event = new Event();
event.setSource("Web UI");
event.setUei(EventConstants.SCHEDOUTAGES_CHANGED_EVENT_UEI);
try {
event.setHost(InetAddress.getLocalHost().getHostName());
} catch (UnknownHostException uhE) {
event.setHost("unresolved.host");
}
event.setTime(EventConstants.formatToString(new java.util.Date()));
try {
EventProxy eventProxy = new TcpEventProxy();
eventProxy.send(event);
} catch (Exception e) {
throw new ServletException("Could not send event " + event.getUei(), e);
}
}
%>
<%
HashMap shortDayNames=new HashMap();
shortDayNames.put("sunday","Sun");
shortDayNames.put("monday","Mon");
shortDayNames.put("tuesday","Tue");
shortDayNames.put("wednesday","Wed");
shortDayNames.put("thursday","Thu");
shortDayNames.put("friday","Fri");
shortDayNames.put("saturday","Sat");
shortDayNames.put("1","1st");
shortDayNames.put("2","2nd");
shortDayNames.put("3","3rd");
shortDayNames.put("4","4th");
shortDayNames.put("5","5th");
shortDayNames.put("6","6th");
shortDayNames.put("7","7th");
shortDayNames.put("8","8th");
shortDayNames.put("9","9th");
shortDayNames.put("10","10th");
shortDayNames.put("11","11th");
shortDayNames.put("12","12th");
shortDayNames.put("13","13th");
shortDayNames.put("14","14th");
shortDayNames.put("15","15th");
shortDayNames.put("16","16th");
shortDayNames.put("17","17th");
shortDayNames.put("18","18th");
shortDayNames.put("19","19th");
shortDayNames.put("20","20th");
shortDayNames.put("21","21st");
shortDayNames.put("22","22nd");
shortDayNames.put("23","23rd");
shortDayNames.put("24","24th");
shortDayNames.put("25","25th");
shortDayNames.put("26","26th");
shortDayNames.put("27","27th");
shortDayNames.put("28","28th");
shortDayNames.put("29","29th");
shortDayNames.put("30","30th");
shortDayNames.put("31","31st");
PollOutagesConfigFactory.init(); //Only init - do *not* reload
PollOutagesConfigFactory pollFactory=PollOutagesConfigFactory.getInstance();
Outage theOutage;
String nameParam=request.getParameter("name");
if(nameParam!=null) {
//first time in - name is passed as a param. Find the outage, copy it, and shove it in the session
//Also keep a copy of the name, for later saving (replacing the original with the edited copy)
Outage tempOutage=pollFactory.getOutage(nameParam);
CharArrayWriter writer=new CharArrayWriter();
tempOutage.marshal(writer);
theOutage=Outage.unmarshal(new CharArrayReader(writer.toCharArray()));
request.getSession().setAttribute("opennms.editoutage",theOutage);
request.getSession().setAttribute("opennms.editoutage.origname", nameParam);
} else if("true".equals(request.getParameter("addNew"))) {
theOutage=new Outage();
//Nuke whitespace - it messes with all sorts of things
theOutage.setName(request.getParameter("newName").trim());
theOutage.setType("specific");
request.getSession().setAttribute("opennms.editoutage",theOutage);
request.getSession().removeAttribute("opennms.editoutage.origname");
} else {
//Neither starting the edit, nor adding a new outage.
theOutage=(Outage)request.getSession().getAttribute("opennms.editoutage");
if(theOutage==null) {
//No name, and no outage in the session. Give up
%> No outage name parameter, nor outage stored in the session. Cannot edit!