public abstract class StaxUtils extends Object
In particular, methods for using StAX (javax.xml.stream
) in combination with
the TrAX API (javax.xml.transform
), and converting StAX readers/writers into SAX
readers/handlers and vice-versa.
Constructor and Description |
---|
StaxUtils() |
Modifier and Type | Method and Description |
---|---|
static ContentHandler |
createContentHandler(XMLEventWriter eventWriter)
Create a SAX
ContentHandler that writes events to the given StAX XMLEventWriter . |
static ContentHandler |
createContentHandler(XMLStreamWriter streamWriter)
Create a SAX
ContentHandler that writes to the given StAX XMLStreamWriter . |
static Result |
createCustomStaxResult(XMLEventWriter eventWriter)
Create a custom, non-JAXP 1.4 StAX
Result for the given XMLEventWriter . |
static Result |
createCustomStaxResult(XMLStreamWriter streamWriter)
Create a custom, non-JAXP 1.4 StAX
Result for the given XMLStreamWriter . |
static Source |
createCustomStaxSource(XMLEventReader eventReader)
Create a custom, non-JAXP 1.4 StAX
Source for the given XMLEventReader . |
static Source |
createCustomStaxSource(XMLStreamReader streamReader)
Create a custom, non-JAXP 1.4 StAX
Source for the given XMLStreamReader . |
static XMLInputFactory |
createDefensiveInputFactory()
Create an
XMLInputFactory with Spring's defensive setup,
i.e. |
static <T extends XMLInputFactory> |
createDefensiveInputFactory(Supplier<T> instanceSupplier)
Variant of
createDefensiveInputFactory() with a custom instance. |
static XMLStreamReader |
createEventStreamReader(XMLEventReader eventReader)
Return a
XMLStreamReader that reads from a XMLEventReader . |
static XMLStreamWriter |
createEventStreamWriter(XMLEventWriter eventWriter)
Return a
XMLStreamWriter that writes to a XMLEventWriter . |
static XMLStreamWriter |
createEventStreamWriter(XMLEventWriter eventWriter,
XMLEventFactory eventFactory)
Return a
XMLStreamWriter that writes to a XMLEventWriter . |
static Result |
createStaxResult(XMLEventWriter eventWriter)
Create a JAXP 1.4
StAXResult for the given XMLEventWriter . |
static Result |
createStaxResult(XMLStreamWriter streamWriter)
Create a JAXP 1.4
StAXResult for the given XMLStreamWriter . |
static Source |
createStaxSource(XMLEventReader eventReader)
Create a JAXP 1.4
StAXSource for the given XMLEventReader . |
static Source |
createStaxSource(XMLStreamReader streamReader)
Create a JAXP 1.4
StAXSource for the given XMLStreamReader . |
static XMLEventReader |
createXMLEventReader(List<XMLEvent> events)
Create a
XMLEventReader from the given list of XMLEvent . |
static XMLReader |
createXMLReader(XMLEventReader eventReader)
Create a SAX
XMLReader that reads from the given StAX XMLEventReader . |
static XMLReader |
createXMLReader(XMLStreamReader streamReader)
Create a SAX
XMLReader that reads from the given StAX XMLStreamReader . |
static XMLEventReader |
getXMLEventReader(Source source)
Return the
XMLEventReader for the given StAX Source. |
static XMLEventWriter |
getXMLEventWriter(Result result)
Return the
XMLEventWriter for the given StAX Result. |
static XMLStreamReader |
getXMLStreamReader(Source source)
Return the
XMLStreamReader for the given StAX Source. |
static XMLStreamWriter |
getXMLStreamWriter(Result result)
Return the
XMLStreamWriter for the given StAX Result. |
static boolean |
isStaxResult(Result result)
Indicate whether the given
Result is a JAXP 1.4 StAX Result or
custom StAX Result. |
static boolean |
isStaxSource(Source source)
Indicate whether the given
Source is a JAXP 1.4 StAX Source or
custom StAX Source. |
public static XMLInputFactory createDefensiveInputFactory()
XMLInputFactory
with Spring's defensive setup,
i.e. no support for the resolution of DTDs and external entities.public static <T extends XMLInputFactory> T createDefensiveInputFactory(Supplier<T> instanceSupplier)
createDefensiveInputFactory()
with a custom instance.instanceSupplier
- supplier for the input factory instancepublic static Source createStaxSource(XMLStreamReader streamReader)
StAXSource
for the given XMLStreamReader
.streamReader
- the StAX stream readerstreamReader
public static Source createStaxSource(XMLEventReader eventReader) throws XMLStreamException
StAXSource
for the given XMLEventReader
.eventReader
- the StAX event readereventReader
XMLStreamException
public static Source createCustomStaxSource(XMLStreamReader streamReader)
Source
for the given XMLStreamReader
.streamReader
- the StAX stream readerstreamReader
public static Source createCustomStaxSource(XMLEventReader eventReader)
Source
for the given XMLEventReader
.eventReader
- the StAX event readereventReader
public static boolean isStaxSource(Source source)
Source
is a JAXP 1.4 StAX Source or
custom StAX Source.true
if source
is a JAXP 1.4 StAXSource
or
custom StAX Source; false
otherwise@Nullable public static XMLStreamReader getXMLStreamReader(Source source)
XMLStreamReader
for the given StAX Source.source
- a JAXP 1.4 StAXSource
XMLStreamReader
IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXSource
or custom StAX Source@Nullable public static XMLEventReader getXMLEventReader(Source source)
XMLEventReader
for the given StAX Source.source
- a JAXP 1.4 StAXSource
XMLEventReader
IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXSource
or custom StAX Sourcepublic static Result createStaxResult(XMLStreamWriter streamWriter)
StAXResult
for the given XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static Result createStaxResult(XMLEventWriter eventWriter)
StAXResult
for the given XMLEventWriter
.eventWriter
- the StAX event writerstreamReader
public static Result createCustomStaxResult(XMLStreamWriter streamWriter)
Result
for the given XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static Result createCustomStaxResult(XMLEventWriter eventWriter)
Result
for the given XMLEventWriter
.eventWriter
- the StAX event writereventWriter
public static boolean isStaxResult(Result result)
Result
is a JAXP 1.4 StAX Result or
custom StAX Result.true
if result
is a JAXP 1.4 StAXResult
or
custom StAX Result; false
otherwise@Nullable public static XMLStreamWriter getXMLStreamWriter(Result result)
XMLStreamWriter
for the given StAX Result.result
- a JAXP 1.4 StAXResult
XMLStreamReader
IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXResult
or custom StAX Result@Nullable public static XMLEventWriter getXMLEventWriter(Result result)
XMLEventWriter
for the given StAX Result.result
- a JAXP 1.4 StAXResult
XMLStreamReader
IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXResult
or custom StAX Resultpublic static XMLEventReader createXMLEventReader(List<XMLEvent> events)
XMLEventReader
from the given list of XMLEvent
.events
- the list of XMLEvents
.XMLEventReader
that reads from the given eventspublic static ContentHandler createContentHandler(XMLStreamWriter streamWriter)
ContentHandler
that writes to the given StAX XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static ContentHandler createContentHandler(XMLEventWriter eventWriter)
ContentHandler
that writes events to the given StAX XMLEventWriter
.eventWriter
- the StAX event writereventWriter
public static XMLReader createXMLReader(XMLStreamReader streamReader)
XMLReader
that reads from the given StAX XMLStreamReader
.streamReader
- the StAX stream readerstreamWriter
public static XMLReader createXMLReader(XMLEventReader eventReader)
XMLReader
that reads from the given StAX XMLEventReader
.eventReader
- the StAX event readereventWriter
public static XMLStreamReader createEventStreamReader(XMLEventReader eventReader) throws XMLStreamException
XMLStreamReader
that reads from a XMLEventReader
.
Useful because the StAX XMLInputFactory
allows one to create an
event reader from a stream reader, but not vice-versa.XMLStreamException
public static XMLStreamWriter createEventStreamWriter(XMLEventWriter eventWriter)
XMLStreamWriter
that writes to a XMLEventWriter
.public static XMLStreamWriter createEventStreamWriter(XMLEventWriter eventWriter, XMLEventFactory eventFactory)
XMLStreamWriter
that writes to a XMLEventWriter
.