public String buildInterfaceTable(String rule, String[] serviceList) throws FilterParseException {
    StringBuffer buffer = new StringBuffer();
    Filter filter = new Filter();
    Map interfaces = filter.getIPServiceMap(rule);

    Iterator i = interfaces.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      buffer.append("<tr><td valign=\"top\">").append(key).append("</td>");
      buffer.append("<td>");

      if (serviceList != null && serviceList.length != 0) {
        Map services = (Map) interfaces.get(key);
        Iterator j = services.keySet().iterator();
        while (j.hasNext()) {
          String svc = (String) j.next();
          for (int idx = 0; idx < serviceList.length; idx++) {
            if (svc.equals(serviceList[idx])) {
              buffer.append(svc).append("<br>");
            }
          }
        }
      } else {
        buffer.append("All services");
      }
      buffer.append("</td>");

      buffer.append("</tr>");
    }

    return buffer.toString();
  }
  public String buildServiceOptions(String rule) throws SQLException {
    List services = NotificationFactory.getInstance().getServiceNames();
    Collections.sort(
        services,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((String) o1).compareToIgnoreCase((String) o2);
          }
        });
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < services.size(); i++) {
      if (rule != null && rule.indexOf((String) services.get(i)) > 0) {
        buffer.append(
            "<option selected VALUE='" + services.get(i) + "'>" + services.get(i) + "</option>");
      } else {
        buffer.append("<option VALUE='" + services.get(i) + "'>" + services.get(i) + "</option>");
      }
    }

    return buffer.toString();
  }
  public String buildPathSelect(String currentPath) throws ServletException {
    StringBuffer buffer = new StringBuffer("<select NAME=\"path\">");

    Map pathsMap = null;

    try {
      pathsMap = new TreeMap(DestinationPathFactory.getInstance().getPaths());
      Iterator iterator = pathsMap.keySet().iterator();
      while (iterator.hasNext()) {
        String key = (String) iterator.next();
        if (key.equals(currentPath)) {
          buffer.append("<option SELECTED VALUE=" + key + ">" + key + "</option>");
        } else {
          buffer.append("<option VALUE=" + key + ">" + key + "</option>");
        }
      }
    } catch (Exception e) {
      throw new ServletException("couldn't get destination path list.", e);
    }
    buffer.append("</select>");

    return buffer.toString();
  }
  public String buildEventSelect(Notification notice) throws IOException, FileNotFoundException {
    // The list of events needs to be transposed to (label, uei) in
    // order to sort it by label for display.
    List eventVendors =
        EventConfigurationManager.getEventsByVendor(NotificationWizardServlet.WT_VENDOR_NAME);
    StringBuffer buffer = new StringBuffer();
    SortedMap sortedEvents = (SortedMap) new TreeMap();

    List excludeList = NotificationWizardServlet.getExcludeList();

    for (Iterator iter = eventVendors.iterator(); iter.hasNext(); ) {
      com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) iter.next();
      sortedEvents.put(e.getLabel(), e);
    }

    Iterator j = sortedEvents.keySet().iterator();

    while (j.hasNext()) {
      String label = (String) j.next();
      com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) sortedEvents.get(label);
      String uei = e.getUei();
      String trimmedUei = NotificationWizardServlet.stripUei(uei);

      if (!excludeList.contains(trimmedUei)) {
        boolean foundUei = NotificationWizardServlet.isEventInNotification(notice, e);
        int id = e.getId();

        if (foundUei) {
          buffer.append("<option selected VALUE=\"" + id + "\">" + label + "</option>");
        } else {
          buffer.append("<option value=\"" + id + "\">" + label + "</option>");
        }
      }
    }

    return buffer.toString();
  }
  public String buildServiceList(String rule) throws SQLException {
    if (rule == null) {
      return "";
    }

    List services = NotificationFactory.getInstance().getServiceNames();
    Collections.sort(
        services,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((String) o1).compareToIgnoreCase((String) o2);
          }
        });
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < services.size(); i++) {
      if (rule.indexOf((String) services.get(i)) > 0) {
        buffer.append(services.get(i)).append("</br>");
      }
    }

    return buffer.toString();
  }
  /**
   * Build a commonly used event list where each event's uei is separated by a </br> tag.
   *
   * @param notice the notification that contains the ueis
   * @return a String representation for the UI
   */
  public String buildEventList(Notification notice) {
    if (notice == null) {
      return "";
    }

    StringBuffer buffer = new StringBuffer();
    for (Iterator iter = notice.getEventInfoCollection().iterator(); iter.hasNext(); ) {
      // create temp event object and use get()
      // NOTE: cannot do this until we also fill in the snmp data
      /*org.opennms.netmgt.xml.event.Event e = EventConfigurationManager.makeEvent(
      		(org.opennms.netmgt.config.notifications.EventInfo)iter.next());
      List events = EventConfigurationManager.get(e);
      */
      List events =
          EventConfigurationManager.getByEventInfo(
              (org.opennms.netmgt.config.notifications.EventInfo) iter.next());
      for (Iterator iter2 = events.iterator(); iter2.hasNext(); ) {
        buffer.append(((Event) iter2.next()).getEventLabel()).append("</br>");
      }
    }

    return buffer.toString();
  }
  /**
   * Builds the vendor events tree.
   *
   * @param notice the selected notification so that events that match this notification can be
   *     preselected
   * @param vendorExcludeList a list of vendors to exclude from the result
   * @return an xml tree of vendors and their events
   */
  public String buildTree(Notification notice, List vendorExcludeList)
      throws IOException, FileNotFoundException {
    StringBuffer buffer = new StringBuffer();
    String itemPrefix = "i_";
    String sectionPrefix = "s_";
    int sid = 1, iid = 1;
    List ueiExcludeList = NotificationWizardServlet.getExcludeList();

    buffer
        .append("<xTree>")
        .append("<item id=\"")
        .append(sectionPrefix)
        .append(sid)
        .append("\">")
        .append("<itemPrimaryData><![CDATA[System Monitoring Events]]></itemPrimaryData>")
        .append("<subitems>");

    List vendors = EventConfigurationManager.getVendorNames();
    for (Iterator iter = vendors.iterator(); iter.hasNext(); ) {
      String vendor = (String) iter.next();

      // Don't show any excluded vendors
      if (vendorExcludeList != null && vendorExcludeList.contains(vendor)) {
        continue;
      }

      sid++;

      buffer
          .append("<item id=\"")
          .append(sectionPrefix)
          .append(sid)
          .append("\">")
          .append("<itemPrimaryData><![CDATA[<input type=\"checkbox\" id=\"c_")
          .append(sectionPrefix)
          .append(sid)
          .append("\" onClick=\"tcs('")
          .append(sectionPrefix)
          .append(sid)
          .append("');us()\">");

      // Write the vendor name
      buffer.append(vendor);

      buffer.append("]]></itemPrimaryData>").append("<subitems>");

      // Now write all the events for the vendor.
      List eventVendors = EventConfigurationManager.getEventsByVendor(vendor);
      SortedMap sortedEvents = (SortedMap) new TreeMap();
      for (Iterator iter2 = eventVendors.iterator(); iter2.hasNext(); ) {
        com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) iter2.next();
        sortedEvents.put(e.getLabel(), e);
      }

      for (Iterator iter2 = sortedEvents.entrySet().iterator(); iter2.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter2.next();
        com.jjlabs.model.EventVendor e = (com.jjlabs.model.EventVendor) entry.getValue();
        String uei = e.getUei();

        if (!ueiExcludeList.contains(NotificationWizardServlet.stripUei(uei))) {
          iid++;
          boolean inNotification = NotificationWizardServlet.isEventInNotification(notice, e);

          buffer
              .append("<item id=\"")
              .append(itemPrefix)
              .append(iid)
              .append("\">")
              .append(
                  "<itemPrimaryData><![CDATA[<input type=\"checkbox\" name=\"tree_check\" id=\"c_")
              .append(itemPrefix)
              .append(iid)
              .append("\" value=\"")
              .append(e.getId())
              .append("\" onClick=\"us()\"")
              .append((inNotification ? " checked" : ""))
              .append(">");

          // Write the event info
          buffer.append(e.getLabel());

          buffer.append("]]></itemPrimaryData>").append("</item>");
        }
      }

      buffer.append("</subitems></item>");
    }

    buffer.append("</subitems></item></xTree>");

    return buffer.toString();
  }