public abstract class StaxUtils
extends java.lang.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 org.xml.sax.ContentHandler |
createContentHandler(javax.xml.stream.XMLEventWriter eventWriter)
Create a SAX
ContentHandler that writes events to the given StAX XMLEventWriter . |
static org.xml.sax.ContentHandler |
createContentHandler(javax.xml.stream.XMLStreamWriter streamWriter)
Create a SAX
ContentHandler that writes to the given StAX XMLStreamWriter . |
static javax.xml.transform.Result |
createCustomStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
Create a custom, non-JAXP 1.4 StAX
Result for the given XMLEventWriter . |
static javax.xml.transform.Result |
createCustomStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
Create a custom, non-JAXP 1.4 StAX
Result for the given XMLStreamWriter . |
static javax.xml.transform.Source |
createCustomStaxSource(javax.xml.stream.XMLEventReader eventReader)
Create a custom, non-JAXP 1.4 StAX
Source for the given XMLEventReader . |
static javax.xml.transform.Source |
createCustomStaxSource(javax.xml.stream.XMLStreamReader streamReader)
Create a custom, non-JAXP 1.4 StAX
Source for the given XMLStreamReader . |
static javax.xml.stream.XMLInputFactory |
createDefensiveInputFactory()
Create an
XMLInputFactory with Spring's defensive setup,
i.e. |
static javax.xml.stream.XMLStreamReader |
createEventStreamReader(javax.xml.stream.XMLEventReader eventReader)
Return a
XMLStreamReader that reads from a XMLEventReader . |
static javax.xml.stream.XMLStreamWriter |
createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter)
Return a
XMLStreamWriter that writes to a XMLEventWriter . |
static javax.xml.stream.XMLStreamWriter |
createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter,
javax.xml.stream.XMLEventFactory eventFactory)
Return a
XMLStreamWriter that writes to a XMLEventWriter . |
static javax.xml.transform.Result |
createStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
Create a JAXP 1.4
StAXResult for the given XMLEventWriter . |
static javax.xml.transform.Result |
createStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
Create a JAXP 1.4
StAXResult for the given XMLStreamWriter . |
static javax.xml.transform.Source |
createStaxSource(javax.xml.stream.XMLEventReader eventReader)
Create a JAXP 1.4
StAXSource for the given XMLEventReader . |
static javax.xml.transform.Source |
createStaxSource(javax.xml.stream.XMLStreamReader streamReader)
Create a JAXP 1.4
StAXSource for the given XMLStreamReader . |
static javax.xml.stream.XMLEventReader |
createXMLEventReader(java.util.List<javax.xml.stream.events.XMLEvent> events)
Create a
XMLEventReader from the given list of XMLEvent . |
static org.xml.sax.XMLReader |
createXMLReader(javax.xml.stream.XMLEventReader eventReader)
Create a SAX
XMLReader that reads from the given StAX XMLEventReader . |
static org.xml.sax.XMLReader |
createXMLReader(javax.xml.stream.XMLStreamReader streamReader)
Create a SAX
XMLReader that reads from the given StAX XMLStreamReader . |
static javax.xml.stream.XMLEventReader |
getXMLEventReader(javax.xml.transform.Source source)
Return the
XMLEventReader for the given StAX Source. |
static javax.xml.stream.XMLEventWriter |
getXMLEventWriter(javax.xml.transform.Result result)
Return the
XMLEventWriter for the given StAX Result. |
static javax.xml.stream.XMLStreamReader |
getXMLStreamReader(javax.xml.transform.Source source)
Return the
XMLStreamReader for the given StAX Source. |
static javax.xml.stream.XMLStreamWriter |
getXMLStreamWriter(javax.xml.transform.Result result)
Return the
XMLStreamWriter for the given StAX Result. |
static boolean |
isStaxResult(javax.xml.transform.Result result)
Indicate whether the given
Result is a JAXP 1.4 StAX Result or
custom StAX Result. |
static boolean |
isStaxSource(javax.xml.transform.Source source)
Indicate whether the given
Source is a JAXP 1.4 StAX Source or
custom StAX Source. |
public static javax.xml.stream.XMLInputFactory createDefensiveInputFactory()
XMLInputFactory
with Spring's defensive setup,
i.e. no support for the resolution of DTDs and external entities.public static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLStreamReader streamReader)
StAXSource
for the given XMLStreamReader
.streamReader
- the StAX stream readerstreamReader
public static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLEventReader eventReader) throws javax.xml.stream.XMLStreamException
StAXSource
for the given XMLEventReader
.eventReader
- the StAX event readereventReader
javax.xml.stream.XMLStreamException
public static javax.xml.transform.Source createCustomStaxSource(javax.xml.stream.XMLStreamReader streamReader)
Source
for the given XMLStreamReader
.streamReader
- the StAX stream readerstreamReader
public static javax.xml.transform.Source createCustomStaxSource(javax.xml.stream.XMLEventReader eventReader)
Source
for the given XMLEventReader
.eventReader
- the StAX event readereventReader
public static boolean isStaxSource(javax.xml.transform.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 javax.xml.stream.XMLStreamReader getXMLStreamReader(javax.xml.transform.Source source)
XMLStreamReader
for the given StAX Source.source
- a JAXP 1.4 StAXSource
XMLStreamReader
java.lang.IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXSource
or custom StAX Source@Nullable public static javax.xml.stream.XMLEventReader getXMLEventReader(javax.xml.transform.Source source)
XMLEventReader
for the given StAX Source.source
- a JAXP 1.4 StAXSource
XMLEventReader
java.lang.IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXSource
or custom StAX Sourcepublic static javax.xml.transform.Result createStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
StAXResult
for the given XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static javax.xml.transform.Result createStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
StAXResult
for the given XMLEventWriter
.eventWriter
- the StAX event writerstreamReader
public static javax.xml.transform.Result createCustomStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
Result
for the given XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static javax.xml.transform.Result createCustomStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
Result
for the given XMLEventWriter
.eventWriter
- the StAX event writereventWriter
public static boolean isStaxResult(javax.xml.transform.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 javax.xml.stream.XMLStreamWriter getXMLStreamWriter(javax.xml.transform.Result result)
XMLStreamWriter
for the given StAX Result.result
- a JAXP 1.4 StAXResult
XMLStreamReader
java.lang.IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXResult
or custom StAX Result@Nullable public static javax.xml.stream.XMLEventWriter getXMLEventWriter(javax.xml.transform.Result result)
XMLEventWriter
for the given StAX Result.result
- a JAXP 1.4 StAXResult
XMLStreamReader
java.lang.IllegalArgumentException
- if source
isn't a JAXP 1.4 StAXResult
or custom StAX Resultpublic static javax.xml.stream.XMLEventReader createXMLEventReader(java.util.List<javax.xml.stream.events.XMLEvent> events)
XMLEventReader
from the given list of XMLEvent
.events
- the list of XMLEvent
s.XMLEventReader
that reads from the given eventspublic static org.xml.sax.ContentHandler createContentHandler(javax.xml.stream.XMLStreamWriter streamWriter)
ContentHandler
that writes to the given StAX XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static org.xml.sax.ContentHandler createContentHandler(javax.xml.stream.XMLEventWriter eventWriter)
ContentHandler
that writes events to the given StAX XMLEventWriter
.eventWriter
- the StAX event writereventWriter
public static org.xml.sax.XMLReader createXMLReader(javax.xml.stream.XMLStreamReader streamReader)
XMLReader
that reads from the given StAX XMLStreamReader
.streamReader
- the StAX stream readerstreamWriter
public static org.xml.sax.XMLReader createXMLReader(javax.xml.stream.XMLEventReader eventReader)
XMLReader
that reads from the given StAX XMLEventReader
.eventReader
- the StAX event readereventWriter
public static javax.xml.stream.XMLStreamReader createEventStreamReader(javax.xml.stream.XMLEventReader eventReader) throws javax.xml.stream.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.javax.xml.stream.XMLStreamException
public static javax.xml.stream.XMLStreamWriter createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter)
XMLStreamWriter
that writes to a XMLEventWriter
.public static javax.xml.stream.XMLStreamWriter createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter, javax.xml.stream.XMLEventFactory eventFactory)
XMLStreamWriter
that writes to a XMLEventWriter
.