public abstract class

StaxUtils

extends Object
java.lang.Object
   ↳ org.springframework.util.xml.StaxUtils

Class Overview

Convenience methods for working with the StAX API.

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.

Summary

Public Constructors
StaxUtils()
Public Methods
static ContentHandler createContentHandler(XMLStreamWriter streamWriter)
Create a SAX ContentHandler that writes to the given StAX XMLStreamWriter.
static ContentHandler createContentHandler(XMLEventWriter eventWriter)
Create a SAX ContentHandler that writes events to the given StAX XMLEventWriter.
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, XMLEventFactory eventFactory)
Return a XMLStreamWriter that writes to a XMLEventWriter.
static Result createStaxResult(XMLStreamWriter streamWriter)
Create a StAX Result for the given XMLStreamWriter.
static Result createStaxResult(XMLEventWriter eventWriter)
Create a StAX Result for the given XMLEventWriter.
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(XMLStreamReader streamReader)
Create a SAX XMLReader that reads from the given StAX XMLStreamReader.
static XMLReader createXMLReader(XMLEventReader eventReader)
Create a SAX XMLReader that reads from the given StAX XMLEventReader.
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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StaxUtils ()

Also: SpringCore

Public Methods

public static ContentHandler createContentHandler (XMLStreamWriter streamWriter)

Also: SpringCore

Create a SAX ContentHandler that writes to the given StAX XMLStreamWriter.

Parameters
streamWriter the StAX stream writer
Returns
  • a content handler writing to the streamWriter

public static ContentHandler createContentHandler (XMLEventWriter eventWriter)

Also: SpringCore

Create a SAX ContentHandler that writes events to the given StAX XMLEventWriter.

Parameters
eventWriter the StAX event writer
Returns
  • a content handler writing to the eventWriter

public static Result createCustomStaxResult (XMLEventWriter eventWriter)

Also: SpringCore

Create a custom, non-JAXP 1.4 StAX Result for the given XMLEventWriter.

Parameters
eventWriter the StAX event writer
Returns
  • a source wrapping the eventWriter

public static Result createCustomStaxResult (XMLStreamWriter streamWriter)

Also: SpringCore

Create a custom, non-JAXP 1.4 StAX Result for the given XMLStreamWriter.

Parameters
streamWriter the StAX stream writer
Returns
  • a source wrapping the streamWriter

public static Source createCustomStaxSource (XMLEventReader eventReader)

Also: SpringCore

Create a custom, non-JAXP 1.4 StAX Source for the given XMLEventReader.

Parameters
eventReader the StAX event reader
Returns
  • a source wrapping the eventReader

public static Source createCustomStaxSource (XMLStreamReader streamReader)

Also: SpringCore

Create a custom, non-JAXP 1.4 StAX Source for the given XMLStreamReader.

Parameters
streamReader the StAX stream reader
Returns
  • a source wrapping the streamReader

public static XMLStreamReader createEventStreamReader (XMLEventReader eventReader)

Also: SpringCore

Return a 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.

Returns
  • a stream reader that reads from an event reader

public static XMLStreamWriter createEventStreamWriter (XMLEventWriter eventWriter, XMLEventFactory eventFactory)

Also: SpringCore

Return a XMLStreamWriter that writes to a XMLEventWriter.

Returns
  • a stream writer that writes to an event writer

public static Result createStaxResult (XMLStreamWriter streamWriter)

Also: SpringCore

Create a StAX Result for the given XMLStreamWriter.

If JAXP 1.4 is available, this method returns a StAXResult; otherwise it returns a custom StAX Result.

Parameters
streamWriter the StAX stream writer
Returns
  • a result wrapping the streamWriter

public static Result createStaxResult (XMLEventWriter eventWriter)

Also: SpringCore

Create a StAX Result for the given XMLEventWriter.

If JAXP 1.4 is available, this method returns a StAXResult; otherwise it returns a custom StAX Result.

Parameters
eventWriter the StAX event writer
Returns
  • a result wrapping streamReader
Throws
XMLStreamException in case of StAX errors

public static Source createStaxSource (XMLEventReader eventReader)

Also: SpringCore

Create a StAX Source for the given XMLEventReader.

If JAXP 1.4 is available, this method returns a StAXSource; otherwise it returns a custom StAX Source.

Parameters
eventReader the StAX event reader
Returns
  • a source wrapping the eventReader
Throws
XMLStreamException in case of StAX errors

public static Source createStaxSource (XMLStreamReader streamReader)

Also: SpringCore

Create a StAX Source for the given XMLStreamReader.

If JAXP 1.4 is available, this method returns a StAXSource; otherwise it returns a custom StAX Source.

Parameters
streamReader the StAX stream reader
Returns
  • a source wrapping the streamReader

public static XMLReader createXMLReader (XMLStreamReader streamReader)

Also: SpringCore

Create a SAX XMLReader that reads from the given StAX XMLStreamReader.

Parameters
streamReader the StAX stream reader
Returns
  • a XMLReader reading from the streamWriter

public static XMLReader createXMLReader (XMLEventReader eventReader)

Also: SpringCore

Create a SAX XMLReader that reads from the given StAX XMLEventReader.

Parameters
eventReader the StAX event reader
Returns
  • a XMLReader reading from the eventWriter

public static XMLEventReader getXMLEventReader (Source source)

Also: SpringCore

Return the XMLEventReader for the given StAX Source.

Parameters
source a custom StAX Source or JAXP 1.4 StAXSource
Returns
Throws
IllegalArgumentException if source is neither a custom StAX Source nor a JAXP 1.4 StAXSource

public static XMLEventWriter getXMLEventWriter (Result result)

Also: SpringCore

Return the XMLEventWriter for the given StAX Result.

Parameters
result a custom StAX Result or JAXP 1.4 StAXResult
Returns
Throws
IllegalArgumentException if source is neither a custom StAX Result nor a JAXP 1.4 StAXResult

public static XMLStreamReader getXMLStreamReader (Source source)

Also: SpringCore

Return the XMLStreamReader for the given StAX Source.

Parameters
source a custom StAX Source or JAXP 1.4 StAXSource
Returns
Throws
IllegalArgumentException if source is neither a custom StAX Source nor JAXP 1.4 StAXSource

public static XMLStreamWriter getXMLStreamWriter (Result result)

Also: SpringCore

Return the XMLStreamWriter for the given StAX Result.

Parameters
result a custom StAX Result or JAXP 1.4 StAXResult
Returns
Throws
IllegalArgumentException if source is neither a custom StAX Result nor a JAXP 1.4 StAXResult

public static boolean isStaxResult (Result result)

Also: SpringCore

Indicate whether the given Result is a StAX Result.

Returns
  • true if result is a custom Stax Result or JAXP 1.4 StAXResult; false otherwise.

public static boolean isStaxSource (Source source)

Also: SpringCore

Indicate whether the given Source is a StAX Source.

Returns
  • true if source is a custom StAX source or JAXP 1.4 StAXSource; false otherwise.