Class XmlEventUtil

    • Method Detail

      • toString

        @NonNull
        public static CharSequence toString​(XMLEvent xmlEvent)
        Generate a message suitable for logging that describes the provided XMLEvent.
        Parameters:
        xmlEvent - the event to generate the message for
        Returns:
        the message
      • toString

        @NonNull
        public static CharSequence toString​(@Nullable
                                            Location location)
        Generates a message for the provided Location.
        Parameters:
        location - the location to generate the message for
        Returns:
        the message
      • toString

        @NonNull
        public static CharSequence toString​(@NonNull
                                            org.codehaus.stax2.XMLStreamReader2 reader)
        Generates a string containing the current event and location of the stream reader.
        Parameters:
        reader - the stream reader
        Returns:
        the generated string
      • toLocation

        @Nullable
        public static Location toLocation​(@NonNull
                                          XMLEvent event)
        Retrieve the resource location of event.
        Parameters:
        event - the event to identify the location for
        Returns:
        the location or null if the location is unknown
      • toQName

        @Nullable
        public static QName toQName​(@NonNull
                                    XMLEvent event)
        Retrieve the name of the node associated with event.
        Parameters:
        event - the event to get the QName for
        Returns:
        the name of the node or null if the event is not a start or end element
      • toEventName

        @NonNull
        public static String toEventName​(@NonNull
                                         XMLEvent event)
        Get the event name of the event.
        Parameters:
        event - the event to get the event name for
        Returns:
        the event name
      • toEventName

        @NonNull
        public static String toEventName​(int eventType)
        Get the event name of the eventType, which is one of the types defined by XMLStreamConstants.
        Parameters:
        eventType - the event constant to get the event name for as defined by XMLStreamConstants
        Returns:
        the event name
      • advanceTo

        @Nullable
        public static XMLEvent advanceTo​(@NonNull
                                         org.codehaus.stax2.XMLEventReader2 reader,
                                         int eventType)
                                  throws XMLStreamException
        Advance through XMLEvents until the event type identified by eventType is reached or the end of stream is found.
        Parameters:
        reader - the event reader to advance
        eventType - the event type to stop on as defined by XMLStreamConstants
        Returns:
        the next event of the specified type or null if the end of stream is reached
        Throws:
        XMLStreamException - if an error occurred while advancing the stream
      • skipProcessingInstructions

        @NonNull
        public static XMLEvent skipProcessingInstructions​(@NonNull
                                                          org.codehaus.stax2.XMLEventReader2 reader)
                                                   throws XMLStreamException
        Skip over any processing instructions.
        Parameters:
        reader - the event reader to advance
        Returns:
        the last processing instruction event or the reader's next event if no processing instruction was found
        Throws:
        XMLStreamException - if an error occurred while advancing the stream
      • skipWhitespace

        @NonNull
        public static XMLEvent skipWhitespace​(@NonNull
                                              org.codehaus.stax2.XMLEventReader2 reader)
                                       throws XMLStreamException
        Skip over any whitespace.
        Parameters:
        reader - the event reader to advance
        Returns:
        the last character event containing whitespace or the reader's next event if no character event was found
        Throws:
        XMLStreamException - if an error occurred while advancing the stream
      • isEventEndElement

        public static boolean isEventEndElement​(XMLEvent event,
                                                @NonNull
                                                QName expectedQName)
        Determine if the event is an end element whose name matches the provided expectedQName.
        Parameters:
        event - the event
        expectedQName - the expected element name
        Returns:
        true if the next event matches the expectedQName
      • isEventEndDocument

        public static boolean isEventEndDocument​(XMLEvent event)
        Determine if the event is an end of document event.
        Parameters:
        event - the event
        Returns:
        true if the next event is an end of document event
      • isEventStartElement

        public static boolean isEventStartElement​(XMLEvent event,
                                                  @NonNull
                                                  QName expectedQName)
                                           throws XMLStreamException
        Determine if the event is a start element whose name matches the provided expectedQName.
        Parameters:
        event - the event
        expectedQName - the expected element name
        Returns:
        true if the next event is a start element that matches the expectedQName
        Throws:
        XMLStreamException - if an error occurred while looking at the next event
      • consumeAndAssert

        public static XMLEvent consumeAndAssert​(org.codehaus.stax2.XMLEventReader2 reader,
                                                int presumedEventType)
                                         throws XMLStreamException
        Consume the next event from reader and assert that this event is of the type identified by presumedEventType.
        Parameters:
        reader - the event reader
        presumedEventType - the expected event type as defined by XMLStreamConstants
        Returns:
        the next event
        Throws:
        XMLStreamException - if an error occurred while looking at the next event
      • consumeAndAssert

        public static XMLEvent consumeAndAssert​(org.codehaus.stax2.XMLEventReader2 reader,
                                                int presumedEventType,
                                                QName presumedName)
                                         throws XMLStreamException
        Consume the next event from reader and assert that this event is of the type identified by presumedEventType and has the name identified by presumedName.
        Parameters:
        reader - the event reader
        presumedEventType - the expected event type as defined by XMLStreamConstants
        presumedName - the expected name of the node associated with the event
        Returns:
        the next event
        Throws:
        XMLStreamException - if an error occurred while looking at the next event
      • assertNext

        public static XMLEvent assertNext​(@NonNull
                                          org.codehaus.stax2.XMLEventReader2 reader,
                                          int presumedEventType)
                                   throws XMLStreamException
        Assert that the next event from reader is of the type identified by presumedEventType.
        Parameters:
        reader - the event reader
        presumedEventType - the expected event type as defined by XMLStreamConstants
        Returns:
        the next event
        Throws:
        XMLStreamException - if an error occurred while looking at the next event
        AssertionError - if the next event does not match the presumed event
      • assertNext

        public static XMLEvent assertNext​(@NonNull
                                          org.codehaus.stax2.XMLEventReader2 reader,
                                          int presumedEventType,
                                          @Nullable
                                          QName presumedName)
                                   throws XMLStreamException
        Assert that the next event from reader is of the type identified by presumedEventType and has the name identified by presumedName.
        Parameters:
        reader - the event reader
        presumedEventType - the expected event type as defined by XMLStreamConstants
        presumedName - the expected name of the node associated with the event
        Returns:
        the next event
        Throws:
        XMLStreamException - if an error occurred while looking at the next event
        AssertionError - if the next event does not match the presumed event
      • skipEvents

        public static XMLEvent skipEvents​(org.codehaus.stax2.XMLEventReader2 reader,
                                          int... events)
                                   throws XMLStreamException
        Skips events specified by events.
        Parameters:
        reader - the event reader
        events - the events to skip
        Returns:
        the next non-mataching event returned by XMLEventReader.peek(), or null if there was no next event
        Throws:
        XMLStreamException - if an error occurred while reading