org.springframework.xml.transform
Class TraxUtils

java.lang.Object
  extended by org.springframework.xml.transform.TraxUtils

public abstract class TraxUtils
extends Object

Convenient utility methods for dealing with TrAX.

Since:
1.5.0
Author:
Arjen Poutsma

Nested Class Summary
static interface TraxUtils.ResultCallback
          Callback interface invoked on each sort of Result.
static interface TraxUtils.SourceCallback
          Callback interface invoked on each sort of Source.
 
Constructor Summary
TraxUtils()
           
 
Method Summary
static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLEventReader eventReader)
          Creates a StAX Source for the given XMLEventReader.
static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLStreamReader streamReader)
          Creates a StAX Source for the given XMLStreamReader.
static void doWithResult(javax.xml.transform.Result result, TraxUtils.ResultCallback callback)
          Performs the given callback operation on a Result.
static void doWithSource(javax.xml.transform.Source source, TraxUtils.SourceCallback callback)
          Performs the given callback operation on a Source.
static org.w3c.dom.Document getDocument(javax.xml.transform.dom.DOMSource source)
          Returns the Document of the given DOMSource.
static javax.xml.stream.XMLEventReader getXMLEventReader(javax.xml.transform.Source source)
          Returns the XMLEventReader for the given StAX Source.
static javax.xml.stream.XMLEventWriter getXMLEventWriter(javax.xml.transform.Result result)
          Returns the XMLEventWriter for the given StAX Result.
static javax.xml.stream.XMLStreamReader getXMLStreamReader(javax.xml.transform.Source source)
          Returns the XMLStreamReader for the given StAX Source.
static javax.xml.stream.XMLStreamWriter getXMLStreamWriter(javax.xml.transform.Result result)
          Returns the XMLStreamWriter for the given StAX Result.
static boolean isStaxResult(javax.xml.transform.Result result)
          Indicates whether the given Result is a StAX Result.
static boolean isStaxSource(javax.xml.transform.Source source)
          Indicates whether the given Source is a StAX Source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraxUtils

public TraxUtils()
Method Detail

isStaxSource

public static boolean isStaxSource(javax.xml.transform.Source source)
Indicates whether the given Source is a StAX Source.

Returns:
true if source is a Spring-WS StaxSource or JAXP 1.4 StAXSource; false otherwise.

isStaxResult

public static boolean isStaxResult(javax.xml.transform.Result result)
Indicates whether the given Result is a StAX Result.

Returns:
true if result is a Spring-WS StaxResult or JAXP 1.4 StAXResult; false otherwise.

getXMLStreamReader

public static javax.xml.stream.XMLStreamReader getXMLStreamReader(javax.xml.transform.Source source)
Returns the XMLStreamReader for the given StAX Source.

Parameters:
source - a Spring-WS StaxSource or StAXSource
Returns:
the XMLStreamReader
Throws:
IllegalArgumentException - if source is neither a Spring-WS StaxSource or StAXSource

getXMLEventReader

public static javax.xml.stream.XMLEventReader getXMLEventReader(javax.xml.transform.Source source)
Returns the XMLEventReader for the given StAX Source.

Parameters:
source - a Spring-WS StaxSource or StAXSource
Returns:
the XMLEventReader
Throws:
IllegalArgumentException - if source is neither a Spring-WS StaxSource or StAXSource

getXMLStreamWriter

public static javax.xml.stream.XMLStreamWriter getXMLStreamWriter(javax.xml.transform.Result result)
Returns the XMLStreamWriter for the given StAX Result.

Parameters:
result - a Spring-WS StaxResult or StAXResult
Returns:
the XMLStreamReader
Throws:
IllegalArgumentException - if source is neither a Spring-WS StaxResult or StAXResult

getXMLEventWriter

public static javax.xml.stream.XMLEventWriter getXMLEventWriter(javax.xml.transform.Result result)
Returns the XMLEventWriter for the given StAX Result.

Parameters:
result - a Spring-WS StaxResult or StAXResult
Returns:
the XMLStreamReader
Throws:
IllegalArgumentException - if source is neither a Spring-WS StaxResult or StAXResult

createStaxSource

public static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLStreamReader streamReader)
Creates a StAX Source for the given XMLStreamReader. Returns a StAXSource under JAXP 1.4 or higher, or a StaxSource otherwise.

Parameters:
streamReader - the StAX stream reader
Returns:
a source wrapping streamReader

createStaxSource

public static javax.xml.transform.Source createStaxSource(javax.xml.stream.XMLEventReader eventReader)
                                                   throws javax.xml.stream.XMLStreamException
Creates a StAX Source for the given XMLEventReader. Returns a StAXSource under JAXP 1.4 or higher, or a StaxSource otherwise.

Parameters:
eventReader - the StAX event reader
Returns:
a source wrapping streamReader
Throws:
javax.xml.stream.XMLStreamException - in case of StAX errors

getDocument

public static org.w3c.dom.Document getDocument(javax.xml.transform.dom.DOMSource source)
Returns the Document of the given DOMSource.

Parameters:
source - the DOM source
Returns:
the document

doWithSource

public static void doWithSource(javax.xml.transform.Source source,
                                TraxUtils.SourceCallback callback)
                         throws javax.xml.stream.XMLStreamException,
                                IOException,
                                org.xml.sax.SAXException
Performs the given callback operation on a Source. Supports both the JAXP 1.4 StAXSource and the Spring-WS StaxSource.

Parameters:
source - source to look at
callback - the callback to invoke for each kind of source
Throws:
javax.xml.stream.XMLStreamException
IOException
org.xml.sax.SAXException

doWithResult

public static void doWithResult(javax.xml.transform.Result result,
                                TraxUtils.ResultCallback callback)
                         throws javax.xml.stream.XMLStreamException,
                                IOException,
                                org.xml.sax.SAXException
Performs the given callback operation on a Result. Supports both the JAXP 1.4 StAXResult and the Spring-WS StaxResult.

Parameters:
result - result to look at
callback - the callback to invoke for each kind of result
Throws:
javax.xml.stream.XMLStreamException
IOException
org.xml.sax.SAXException


Copyright © 2010. All Rights Reserved.