static Set<String> getNamespaces(XmlElement element) {
   Set<String> result = new HashSet<>();
   for (Entry<String, Attr> attribute : element.getAttributes().entrySet()) {
     if (attribute.getKey().startsWith("xmlns")) {
       result.add(attribute.getValue().getValue());
     }
   }
   for (XmlElement child : element.getChildElements()) {
     result.addAll(getNamespaces(child));
   }
   return result;
 }
コード例 #2
0
  // FIXME move somewhere to util
  private static Map.Entry<Date, XmlElement> stripNotification(final NetconfMessage message) {
    final XmlElement xmlElement = XmlElement.fromDomDocument(message.getDocument());
    final List<XmlElement> childElements = xmlElement.getChildElements();
    Preconditions.checkArgument(
        childElements.size() == 2, "Unable to parse notification %s, unexpected format", message);

    final XmlElement eventTimeElement;
    final XmlElement notificationElement;

    if (childElements.get(0).getName().equals(EVENT_TIME)) {
      eventTimeElement = childElements.get(0);
      notificationElement = childElements.get(1);
    } else if (childElements.get(1).getName().equals(EVENT_TIME)) {
      eventTimeElement = childElements.get(1);
      notificationElement = childElements.get(0);
    } else {
      throw new IllegalArgumentException(
          "Notification payload does not contain " + EVENT_TIME + " " + message);
    }

    try {
      return new AbstractMap.SimpleEntry<>(
          EVENT_TIME_FORMAT.get().parse(eventTimeElement.getTextContent()), notificationElement);
    } catch (DocumentedException e) {
      throw new IllegalArgumentException(
          "Notification payload does not contain " + EVENT_TIME + " " + message);
    } catch (ParseException e) {
      LOG.warn(
          "Unable to parse event time from {}. Setting time to {}",
          eventTimeElement,
          NetconfNotification.UNKNOWN_EVENT_TIME,
          e);
      return new AbstractMap.SimpleEntry<>(
          NetconfNotification.UNKNOWN_EVENT_TIME, notificationElement);
    }
  }