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 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 StAX
Result for the given XMLEventWriter . |
static Result |
createStaxResult(XMLStreamWriter streamWriter)
Create a StAX
Result for the given XMLStreamWriter . |
static Source |
createStaxSource(XMLEventReader eventReader)
Create a StAX
Source for the given XMLEventReader . |
static Source |
createStaxSource(XMLStreamReader streamReader)
Create a StAX
Source for the given XMLStreamReader . |
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 StAX Result. |
static boolean |
isStaxSource(Source source)
Indicate whether the given
Source is a StAX Source. |
public static Source createCustomStaxSource(XMLStreamReader streamReader)
Source
for the given XMLStreamReader
.streamReader
- the StAX stream readerstreamReader
public static Source createStaxSource(XMLStreamReader streamReader)
Source
for the given XMLStreamReader
.
If JAXP 1.4 is available, this method returns a StAXSource
;
otherwise it returns a custom StAX Source.
streamReader
- the StAX stream readerstreamReader
createCustomStaxSource(XMLStreamReader)
public static Source createCustomStaxSource(XMLEventReader eventReader)
Source
for the given XMLEventReader
.eventReader
- the StAX event readereventReader
public static Source createStaxSource(XMLEventReader eventReader) throws XMLStreamException
Source
for the given XMLEventReader
.
If JAXP 1.4 is available, this method returns a StAXSource
;
otherwise it returns a custom StAX Source.
eventReader
- the StAX event readereventReader
XMLStreamException
- in case of StAX errorscreateCustomStaxSource(XMLEventReader)
public static boolean isStaxSource(Source source)
Source
is a StAX Source.true
if source
is a custom StAX source or JAXP
1.4 StAXSource
; false
otherwise.public static Result createCustomStaxResult(XMLStreamWriter streamWriter)
Result
for the given XMLStreamWriter
.streamWriter
- the StAX stream writerstreamWriter
public static Result createStaxResult(XMLStreamWriter streamWriter)
Result
for the given XMLStreamWriter
.
If JAXP 1.4 is available, this method returns a StAXResult
;
otherwise it returns a custom StAX Result.
streamWriter
- the StAX stream writerstreamWriter
createCustomStaxResult(XMLStreamWriter)
public static Result createCustomStaxResult(XMLEventWriter eventWriter)
Result
for the given XMLEventWriter
.eventWriter
- the StAX event writereventWriter
public static Result createStaxResult(XMLEventWriter eventWriter) throws XMLStreamException
Result
for the given XMLEventWriter
.
If JAXP 1.4 is available, this method returns a StAXResult
; otherwise it returns a
custom StAX Result.
eventWriter
- the StAX event writerstreamReader
XMLStreamException
- in case of StAX errorscreateCustomStaxResult(XMLEventWriter)
public static boolean isStaxResult(Result result)
Result
is a StAX Result.true
if result
is a custom Stax Result or JAXP 1.4
StAXResult
; false
otherwise.public static XMLStreamReader getXMLStreamReader(Source source)
XMLStreamReader
for the given StAX Source.source
- a custom StAX Source or
JAXP 1.4 StAXSource
XMLStreamReader
IllegalArgumentException
- if source
is neither a custom StAX Source
nor JAXP 1.4 StAXSource
public static XMLEventReader getXMLEventReader(Source source)
XMLEventReader
for the given StAX Source.source
- a custom StAX Source or
JAXP 1.4 StAXSource
XMLEventReader
IllegalArgumentException
- if source
is neither a custom StAX Source
nor a JAXP 1.4 StAXSource
public static XMLStreamWriter getXMLStreamWriter(Result result)
XMLStreamWriter
for the given StAX Result.result
- a custom StAX Result or
JAXP 1.4 StAXResult
XMLStreamReader
IllegalArgumentException
- if source
is neither a custom StAX Result
nor a JAXP 1.4 StAXResult
public static XMLEventWriter getXMLEventWriter(Result result)
XMLEventWriter
for the given StAX Result.result
- a custom StAX Result or
JAXP 1.4 StAXResult
XMLStreamReader
IllegalArgumentException
- if source
is neither a custom StAX Result
nor a JAXP 1.4 StAXResult
public 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 a 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
.