java.lang.Object | ||
↳ | javax.xml.transform.sax.SAXSource | |
↳ | com.thoughtworks.xstream.io.xml.TraxSource |
A SAXSource JAXP TrAX Source that enables using XStream object serialization as direct input for XSLT processors without resorting to an intermediate representation such as text XML, DOM or DOM4J.
The following example shows how to apply an XSL Transformation to a set of Java objects gathered into a List (source
):
public static String transform(List source, String stylesheet) {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer(
new StreamSource(stylesheet));
TraxSource in = new TraxSource(source);
Writer out = new StringWriter();
transformer.transform(in, new StreamResult(out));
return out.toString();
} catch (TransformerException e) {
throw new RuntimeException("XSLT Transformation failed", e);
}
}
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | XSTREAM_FEATURE | If getFeature(String) returns true
when passed this value as an argument, the Transformer natively supports XStream. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
javax.xml.transform.sax.SAXSource
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a XStream TrAX source.
| |||||||||||
Creates a XStream TrAX source, specifying the object to marshal.
| |||||||||||
Creates a XStream TrAX source, specifying the object to marshal and a configured (with
aliases) XStream facade.
| |||||||||||
Creates a XStream TrAX source, setting the objects to marshal.
| |||||||||||
Creates a XStream TrAX source, setting the objects to marshal and a configured (with
aliases) XStream facade.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the XMLReader to be used for the Source.
| |||||||||||
Sets the SAX InputSource to be used for the Source.
| |||||||||||
Sets the object to marshal.
| |||||||||||
Sets the list of objects to marshal.
| |||||||||||
Set the XMLReader to be used for the Source.
| |||||||||||
Sets the XStream facade to use when marshalling objects.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
javax.xml.transform.sax.SAXSource
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
javax.xml.transform.Source
|
If getFeature(String)
returns true
when passed this value as an argument, the Transformer natively supports XStream.
FEATURE
value defined by its superclass to be considered as a SAXSource
by Transformer implementations not natively supporting this XStream-specific source
Creates a XStream TrAX source.
Creates a XStream TrAX source, specifying the object to marshal.
source | the object to marshal. |
---|
IllegalArgumentException | if source is null . |
---|
Creates a XStream TrAX source, specifying the object to marshal and a configured (with aliases) XStream facade.
source | the object to marshal. |
---|---|
xstream | a configured XStream facade. |
IllegalArgumentException | if source or xstream is
null . |
---|
Creates a XStream TrAX source, setting the objects to marshal.
source | the list of objects to marshal. |
---|
IllegalArgumentException | if source is null or
empty. |
---|
Creates a XStream TrAX source, setting the objects to marshal and a configured (with aliases) XStream facade.
source | the list of objects to marshal. |
---|---|
xstream | a configured XStream facade. |
IllegalArgumentException | if source or xstream is
null or source is empty. |
---|
Returns the XMLReader to be used for the Source.
This implementation returns a specific XMLReader (SaxWriter
) generating the XML from a list of input objects.
Sets the SAX InputSource to be used for the Source.
As this implementation only supports object lists as data source, this method always throws an UnsupportedOperationException.inputSource | a valid InputSource reference. |
---|
UnsupportedOperationException | always! |
---|
Sets the object to marshal.
obj | the object to marshal. |
---|
IllegalArgumentException | if source is null .
|
---|
Sets the list of objects to marshal.
When dealing with non-text input (such as SAX or DOM), XSLT processors support multiple root node children for the source tree (see section 3.1 of the "XSL Transformations (XSLT) Version 1.0" specification. Using a list of objects as source makes use of this feature and allows creating XML documents merging the XML serialization of several Java objects.list | the list of objects to marshal. |
---|
IllegalArgumentException | if source is null or
empty.
|
---|
Set the XMLReader to be used for the Source.
As this implementation only supports object lists as data source, this method throws anUnsupportedOperationException
if the provided reader object does not implement the SAX XMLFilter interface.
Otherwise, a SaxWriter
instance will be attached as parent of the filter chain.
reader | a valid XMLReader or XMLFilter reference. |
---|
UnsupportedOperationException | if reader is not a SAX
XMLFilter. |
---|
Sets the XStream facade to use when marshalling objects.
xstream | a configured XStream facade. |
---|
IllegalArgumentException | if xstream is null .
|
---|