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);
}
}
| Modifier and Type | Field and Description |
|---|---|
| private List | source
The list of Java objects to be serialized. |
| private XMLReader | xmlReader
The XMLReader object associated to this source or |
| private XStream | xstream
The configured XStream facade to use for serializing objects. |
| public static final String | XSTREAM_FEATURE
If |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TraxSource(Object
the object to marshal. source)Creates a XStream TrAX source, specifying the object to marshal. |
| public | TraxSource(Object
the object to marshal. source, XStream a configured XStream facade. xstream)Creates a XStream TrAX source, specifying the object to marshal and a configured (with aliases) XStream facade. |
| public | TraxSource(List<E>
the list of objects to marshal. source)Creates a XStream TrAX source, setting the objects to marshal. |
| public | TraxSource(List<E>
the list of objects to marshal. source, XStream a configured XStream facade. xstream)Creates a XStream TrAX source, setting the objects to marshal and a configured (with aliases) XStream facade. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| public XMLReader | Returns: an XMLReader generating the XML from a list of input objects. |
| public void | setInputSource(InputSource
a valid InputSource reference. inputSource)
Sets the SAX InputSource to be used for the Source.
|
| public void | |
| public void | |
| public void | setXMLReader(XMLReader
a valid XMLReader or XMLFilter reference. reader)
Set the XMLReader to be used for the Source.
|
| public void | setXStream(XStream
a configured XStream facade. xstream)Sets the XStream facade to use when marshalling objects. |
| source | back to summary |
|---|---|
| private List<E> source The list of Java objects to be serialized. | |
| xmlReader | back to summary |
|---|---|
| private XMLReader xmlReader The XMLReader object associated to this source or
| |
| xstream | back to summary |
|---|---|
| private XStream xstream The configured XStream facade to use for serializing objects. | |
| XSTREAM_FEATURE | back to summary |
|---|---|
| public static final String XSTREAM_FEATURE If Note This implementation does not override the
| |
| TraxSource | back to summary |
|---|---|
| public TraxSource() Creates a XStream TrAX source. | |
| TraxSource | back to summary |
|---|---|
| public TraxSource(Object source) Creates a XStream TrAX source, specifying the object to marshal.
| |
| TraxSource | back to summary |
|---|---|
| public TraxSource(Object source, XStream xstream) Creates a XStream TrAX source, specifying the object to marshal and a configured (with aliases) XStream facade.
| |
| TraxSource | back to summary |
|---|---|
| public TraxSource(List<E> source) Creates a XStream TrAX source, setting the objects to marshal.
| |
| TraxSource | back to summary |
|---|---|
| public TraxSource(List<E> source, XStream xstream) Creates a XStream TrAX source, setting the objects to marshal and a configured (with aliases) XStream facade.
| |
| configureXMLReader | back to summary |
|---|---|
| private void configureXMLReader() | |
| createXMLReader | back to summary |
|---|---|
| private void createXMLReader(XMLReader filterChain) | |
| getXMLReader | back to summary |
|---|---|
| public XMLReader getXMLReader() Overrides javax. Returns the XMLReader to be used for the Source.
This implementation returns a
specific XMLReader (
| |
| setInputSource | back to summary |
|---|---|
| public void setInputSource(InputSource inputSource) Overrides javax. 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
| |
| setSource | back to summary |
|---|---|
| public void setSource(Object obj) Sets the object to marshal.
| |
| setSourceAsList | back to summary |
|---|---|
| public void setSourceAsList(List<E> list) 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.
| |
| setXMLReader | back to summary |
|---|---|
| public void setXMLReader(XMLReader reader) Overrides javax. Set the XMLReader to be used for the Source.
As this implementation only supports
object lists as data source, this method throws an
| |
| setXStream | back to summary |
|---|---|
| public void setXStream(XStream xstream) Sets the XStream facade to use when marshalling objects.
| |