Class XmlEventUtil
- java.lang.Object
-
- gov.nist.secauto.metaschema.core.model.util.XmlEventUtil
-
public final class XmlEventUtil extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XMLEvent
advanceTo(org.codehaus.stax2.XMLEventReader2 reader, int eventType)
Advance through XMLEvents until the event type identified byeventType
is reached or the end of stream is found.static XMLEvent
assertNext(org.codehaus.stax2.XMLEventReader2 reader, int presumedEventType)
Assert that the next event fromreader
is of the type identified bypresumedEventType
.static XMLEvent
assertNext(org.codehaus.stax2.XMLEventReader2 reader, int presumedEventType, QName presumedName)
Assert that the next event fromreader
is of the type identified bypresumedEventType
and has the name identified bypresumedName
.static XMLEvent
consumeAndAssert(org.codehaus.stax2.XMLEventReader2 reader, int presumedEventType)
Consume the next event fromreader
and assert that this event is of the type identified bypresumedEventType
.static XMLEvent
consumeAndAssert(org.codehaus.stax2.XMLEventReader2 reader, int presumedEventType, QName presumedName)
Consume the next event fromreader
and assert that this event is of the type identified bypresumedEventType
and has the name identified bypresumedName
.static CharSequence
generateExpectedMessage(XMLEvent event, int presumedEventType, QName presumedName)
static CharSequence
generateLocationMessage(XMLEvent event)
static CharSequence
generateLocationMessage(Location location)
static boolean
isEventEndDocument(XMLEvent event)
Determine if theevent
is an end of document event.static boolean
isEventEndElement(XMLEvent event, QName expectedQName)
Determine if theevent
is an end element whose name matches the providedexpectedQName
.static boolean
isEventStartElement(XMLEvent event, QName expectedQName)
Determine if theevent
is a start element whose name matches the providedexpectedQName
.static XMLEvent
skipEvents(org.codehaus.stax2.XMLEventReader2 reader, int... events)
Skips events specified byevents
.static XMLEvent
skipProcessingInstructions(org.codehaus.stax2.XMLEventReader2 reader)
Skip over any processing instructions.static XMLEvent
skipWhitespace(org.codehaus.stax2.XMLEventReader2 reader)
Skip over any whitespace.static String
toEventName(int eventType)
Get the event name of theeventType
, which is one of the types defined byXMLStreamConstants
.static String
toEventName(XMLEvent event)
Get the event name of theevent
.static Location
toLocation(XMLEvent event)
Retrieve the resource location ofevent
.static QName
toQName(XMLEvent event)
Retrieve the name of the node associated withevent
.static CharSequence
toString(XMLEvent xmlEvent)
Generate a message suitable for logging that describes the providedXMLEvent
.static CharSequence
toString(Location location)
Generates a message for the providedLocation
.static CharSequence
toString(org.codehaus.stax2.XMLStreamReader2 reader)
Generates a string containing the current event and location of the stream reader.
-
-
-
Method Detail
-
toString
@NonNull public static CharSequence toString(XMLEvent xmlEvent)
Generate a message suitable for logging that describes the providedXMLEvent
.- 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 providedLocation
.- 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 ofevent
.- 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 withevent
.- Parameters:
event
- the event to get theQName
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 theevent
.- 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 theeventType
, which is one of the types defined byXMLStreamConstants
.- Parameters:
eventType
- the event constant to get the event name for as defined byXMLStreamConstants
- 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 byeventType
is reached or the end of stream is found.- Parameters:
reader
- the event reader to advanceeventType
- the event type to stop on as defined byXMLStreamConstants
- 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 theevent
is an end element whose name matches the providedexpectedQName
.- Parameters:
event
- the eventexpectedQName
- the expected element name- Returns:
true
if the next event matches theexpectedQName
-
isEventEndDocument
public static boolean isEventEndDocument(XMLEvent event)
Determine if theevent
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 theevent
is a start element whose name matches the providedexpectedQName
.- Parameters:
event
- the eventexpectedQName
- the expected element name- Returns:
true
if the next event is a start element that matches theexpectedQName
- 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 fromreader
and assert that this event is of the type identified bypresumedEventType
.- Parameters:
reader
- the event readerpresumedEventType
- the expected event type as defined byXMLStreamConstants
- 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 fromreader
and assert that this event is of the type identified bypresumedEventType
and has the name identified bypresumedName
.- Parameters:
reader
- the event readerpresumedEventType
- the expected event type as defined byXMLStreamConstants
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 fromreader
is of the type identified bypresumedEventType
.- Parameters:
reader
- the event readerpresumedEventType
- the expected event type as defined byXMLStreamConstants
- Returns:
- the next event
- Throws:
XMLStreamException
- if an error occurred while looking at the next eventAssertionError
- 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 fromreader
is of the type identified bypresumedEventType
and has the name identified bypresumedName
.- Parameters:
reader
- the event readerpresumedEventType
- the expected event type as defined byXMLStreamConstants
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 eventAssertionError
- if the next event does not match the presumed event
-
generateLocationMessage
public static CharSequence generateLocationMessage(@NonNull XMLEvent event)
-
generateLocationMessage
public static CharSequence generateLocationMessage(@NonNull Location location)
-
generateExpectedMessage
public static CharSequence generateExpectedMessage(@Nullable XMLEvent event, int presumedEventType, @Nullable QName presumedName)
-
skipEvents
public static XMLEvent skipEvents(org.codehaus.stax2.XMLEventReader2 reader, int... events) throws XMLStreamException
Skips events specified byevents
.- Parameters:
reader
- the event readerevents
- the events to skip- Returns:
- the next non-mataching event returned by
XMLEventReader.peek()
, ornull
if there was no next event - Throws:
XMLStreamException
- if an error occurred while reading
-
-