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.
Modifier and Type | Class and Description |
---|---|
private static class |
StaxUtils.Jaxp14StaxHandler
Inner class to avoid a static JAXP 1.4 dependency.
|
Modifier and Type | Field and Description |
---|---|
private static boolean |
jaxp14Available |
Constructor and Description |
---|
StaxUtils() |
Modifier and Type | Method and Description |
---|---|
static org.xml.sax.ContentHandler |
createContentHandler(javax.xml.stream.XMLEventWriter eventWriter)
Create a SAX <code>ContentHandler</code> that writes events to the given StAX <code>XMLEventWriter</code>.
|
static org.xml.sax.ContentHandler |
createContentHandler(javax.xml.stream.XMLStreamWriter streamWriter)
Create a SAX <code>ContentHandler</code> that writes to the given StAX <code>XMLStreamWriter</code>.
|
static javax.xml.transform.Result |
createCustomStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
Create a custom, non-JAXP 1.4 StAX <code>Result</code> for the given <code>XMLEventWriter</code>.
|
static javax.xml.transform.Result |
createCustomStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
Create a custom, non-JAXP 1.4 StAX <code>Result</code> for the given <code>XMLStreamWriter</code>.
|
static javax.xml.transform.Source |
createCustomStaxSource(javax.xml.stream.XMLEventReader eventReader)
Create a custom, non-JAXP 1.4 StAX <code>Source</code> for the given <code>XMLEventReader</code>.
|
static javax.xml.transform.Source |
createCustomStaxSource(javax.xml.stream.XMLStreamReader streamReader)
Create a custom, non-JAXP 1.4 StAX <code>Source</code> for the given <code>XMLStreamReader</code>.
|
static javax.xml.stream.XMLStreamReader |
createEventStreamReader(javax.xml.stream.XMLEventReader eventReader)
Return a <code>XMLStreamReader</code> that reads from a <code>XMLEventReader</code>.
|
static javax.xml.stream.XMLStreamWriter |
createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter)
Return a <code>XMLStreamWriter</code> that writes to a <code>XMLEventWriter</code>.
|
static javax.xml.stream.XMLStreamWriter |
createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter,
javax.xml.stream.XMLEventFactory eventFactory)
Return a <code>XMLStreamWriter</code> that writes to a <code>XMLEventWriter</code>.
|
static javax.xml.transform.Result |
createStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
Create a StAX <code>Result</code> for the given <code>XMLEventWriter</code>.
|
static javax.xml.transform.Result |
createStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
Create a StAX <code>Result</code> for the given <code>XMLStreamWriter</code>.
|
static javax.xml.transform.Source |
createStaxSource(javax.xml.stream.XMLEventReader eventReader)
Create a StAX <code>Source</code> for the given <code>XMLEventReader</code>.
|
static javax.xml.transform.Source |
createStaxSource(javax.xml.stream.XMLStreamReader streamReader)
Create a StAX <code>Source</code> for the given <code>XMLStreamReader</code>.
|
static org.xml.sax.XMLReader |
createXMLReader(javax.xml.stream.XMLEventReader eventReader)
Create a SAX <code>XMLReader</code> that reads from the given StAX <code>XMLEventReader</code>.
|
static org.xml.sax.XMLReader |
createXMLReader(javax.xml.stream.XMLStreamReader streamReader)
Create a SAX <code>XMLReader</code> that reads from the given StAX <code>XMLStreamReader</code>.
|
static javax.xml.stream.XMLEventReader |
getXMLEventReader(javax.xml.transform.Source source)
Return the <code>XMLEventReader</code> for the given StAX Source.
|
static javax.xml.stream.XMLEventWriter |
getXMLEventWriter(javax.xml.transform.Result result)
Return the <code>XMLEventWriter</code> for the given StAX Result.
|
static javax.xml.stream.XMLStreamReader |
getXMLStreamReader(javax.xml.transform.Source source)
Return the <code>XMLStreamReader</code> for the given StAX Source.
|
static javax.xml.stream.XMLStreamWriter |
getXMLStreamWriter(javax.xml.transform.Result result)
Return the <code>XMLStreamWriter</code> for the given StAX Result.
|
static boolean |
isStaxResult(javax.xml.transform.Result result)
Indicate whether the given <code>Result</code> is a StAX Result.
|
static boolean |
isStaxSource(javax.xml.transform.Source source)
Indicate whether the given <code>Source</code> is a StAX Source.
|
public static javax.xml.transform.Source createCustomStaxSource(javax.xml.stream.XMLStreamReader streamReader)
streamReader
- the StAX stream readerstreamReader
public static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLStreamReader streamReader)
If JAXP 1.4 is available, this method returns a <code>StAXSource</code>; otherwise it returns a custom StAX Source.
streamReader
- the StAX stream readerstreamReader
createCustomStaxSource(XMLStreamReader)
public static javax.xml.transform.Source createCustomStaxSource(javax.xml.stream.XMLEventReader eventReader)
eventReader
- the StAX event readereventReader
public static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLEventReader eventReader) throws javax.xml.stream.XMLStreamException
If JAXP 1.4 is available, this method returns a <code>StAXSource</code>; otherwise it returns a custom StAX Source.
eventReader
- the StAX event readereventReader
javax.xml.stream.XMLStreamException
- in case of StAX errorscreateCustomStaxSource(XMLEventReader)
public static boolean isStaxSource(javax.xml.transform.Source source)
true
if source
is a custom StAX source or JAXP
1.4 <code>StAXSource</code>; false
otherwise.public static javax.xml.transform.Result createCustomStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
streamWriter
- the StAX stream writerstreamWriter
public static javax.xml.transform.Result createStaxResult(javax.xml.stream.XMLStreamWriter streamWriter)
If JAXP 1.4 is available, this method returns a <code>StAXResult</code>; otherwise it returns a custom StAX Result.
streamWriter
- the StAX stream writerstreamWriter
createCustomStaxResult(XMLStreamWriter)
public static javax.xml.transform.Result createCustomStaxResult(javax.xml.stream.XMLEventWriter eventWriter)
eventWriter
- the StAX event writereventWriter
public static javax.xml.transform.Result createStaxResult(javax.xml.stream.XMLEventWriter eventWriter) throws javax.xml.stream.XMLStreamException
If JAXP 1.4 is available, this method returns a <code>StAXResult</code>; otherwise it returns a custom StAX Result.
eventWriter
- the StAX event writerstreamReader
javax.xml.stream.XMLStreamException
- in case of StAX errorscreateCustomStaxResult(XMLEventWriter)
public static boolean isStaxResult(javax.xml.transform.Result result)
true
if result
is a custom Stax Result or JAXP 1.4
<code>StAXResult</code>; false
otherwise.public static javax.xml.stream.XMLStreamReader getXMLStreamReader(javax.xml.transform.Source source)
source
- a custom StAX Source or
JAXP 1.4 <code>StAXSource</code>java.lang.IllegalArgumentException
- if source
is neither a custom StAX Source
nor JAXP 1.4 <code>StAXSource</code>public static javax.xml.stream.XMLEventReader getXMLEventReader(javax.xml.transform.Source source)
source
- a custom StAX Source or
JAXP 1.4 <code>StAXSource</code>java.lang.IllegalArgumentException
- if source
is neither a custom StAX Source
nor a JAXP 1.4 <code>StAXSource</code>public static javax.xml.stream.XMLStreamWriter getXMLStreamWriter(javax.xml.transform.Result result)
result
- a custom StAX Result or
JAXP 1.4 <code>StAXResult</code>java.lang.IllegalArgumentException
- if source
is neither a custom StAX Result
nor a JAXP 1.4 <code>StAXResult</code>public static javax.xml.stream.XMLEventWriter getXMLEventWriter(javax.xml.transform.Result result)
result
- a custom StAX Result or
JAXP 1.4 <code>StAXResult</code>java.lang.IllegalArgumentException
- if source
is neither a custom StAX Result
nor a JAXP 1.4 <code>StAXResult</code>public static org.xml.sax.ContentHandler createContentHandler(javax.xml.stream.XMLStreamWriter streamWriter)
streamWriter
- the StAX stream writerstreamWriter
public static org.xml.sax.ContentHandler createContentHandler(javax.xml.stream.XMLEventWriter eventWriter)
eventWriter
- the StAX event writereventWriter
public static org.xml.sax.XMLReader createXMLReader(javax.xml.stream.XMLStreamReader streamReader)
streamReader
- the StAX stream readerstreamWriter
public static org.xml.sax.XMLReader createXMLReader(javax.xml.stream.XMLEventReader eventReader)
eventReader
- the StAX event readereventWriter
public static javax.xml.stream.XMLStreamReader createEventStreamReader(javax.xml.stream.XMLEventReader eventReader) throws javax.xml.stream.XMLStreamException
XMLInputFactory
allows one to create a 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)
public static javax.xml.stream.XMLStreamWriter createEventStreamWriter(javax.xml.stream.XMLEventWriter eventWriter, javax.xml.stream.XMLEventFactory eventFactory)