public class TraxSource extends 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);
}
}
Modifier and Type | Field and Description |
---|---|
static String |
XSTREAM_FEATURE
If
TransformerFactory.getFeature(java.lang.String) returns true
when passed this value as an argument, the Transformer natively supports XStream. |
Constructor and Description |
---|
TraxSource()
Creates a XStream TrAX source.
|
TraxSource(List source)
Creates a XStream TrAX source, setting the objects to marshal.
|
TraxSource(List source,
XStream xstream)
Creates a XStream TrAX source, setting the objects to marshal and a configured (with
aliases) XStream facade.
|
TraxSource(Object source)
Creates a XStream TrAX source, specifying the object to marshal.
|
TraxSource(Object source,
XStream xstream)
Creates a XStream TrAX source, specifying the object to marshal and a configured (with
aliases) XStream facade.
|
Modifier and Type | Method and Description |
---|---|
XMLReader |
getXMLReader()
Returns the XMLReader to be used for the Source.
|
void |
setInputSource(InputSource inputSource)
Sets the SAX InputSource to be used for the Source.
|
void |
setSource(Object obj)
Sets the object to marshal.
|
void |
setSourceAsList(List list)
Sets the list of objects to marshal.
|
void |
setXMLReader(XMLReader reader)
Set the XMLReader to be used for the Source.
|
void |
setXStream(XStream xstream)
Sets the XStream facade to use when marshalling objects.
|
getInputSource, getSystemId, setSystemId, sourceToInputSource
public static final String XSTREAM_FEATURE
TransformerFactory.getFeature(java.lang.String)
returns true
when passed this value as an argument, the Transformer natively supports XStream.
Note: This implementation does not override the
SAXSource.FEATURE
value defined by its superclass to be considered as a SAXSource
by Transformer implementations not natively supporting this XStream-specific source
public TraxSource()
public TraxSource(Object source)
source
- the object to marshal.IllegalArgumentException
- if source
is null
.setSource(java.lang.Object)
public TraxSource(Object source, XStream xstream)
source
- the object to marshal.xstream
- a configured XStream facade.IllegalArgumentException
- if source
or xstream
is
null
.setSource(java.lang.Object)
,
setXStream(com.thoughtworks.xstream.XStream)
public TraxSource(List source)
source
- the list of objects to marshal.IllegalArgumentException
- if source
is null
or
empty.setSourceAsList(java.util.List)
public TraxSource(List source, XStream xstream)
source
- the list of objects to marshal.xstream
- a configured XStream facade.IllegalArgumentException
- if source
or xstream
is
null
or source
is empty.setSourceAsList(java.util.List)
,
setXStream(com.thoughtworks.xstream.XStream)
public void setInputSource(InputSource inputSource)
As this implementation only
supports object lists as data source, this method always throws an
UnsupportedOperationException
.
setInputSource
in class SAXSource
inputSource
- a valid InputSource reference.UnsupportedOperationException
- always!public void setXMLReader(XMLReader reader)
As this implementation only supports
object lists as data source, this method throws an UnsupportedOperationException
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.
setXMLReader
in class SAXSource
reader
- a valid XMLReader or XMLFilter reference.UnsupportedOperationException
- if reader
is not a SAX
XMLFilter
.getXMLReader()
public XMLReader getXMLReader()
This implementation returns a
specific XMLReader (SaxWriter
) generating the XML from a list of input objects.
getXMLReader
in class SAXSource
public void setXStream(XStream xstream)
xstream
- a configured XStream facade.IllegalArgumentException
- if xstream
is null
.public void setSource(Object obj)
obj
- the object to marshal.IllegalArgumentException
- if source
is null
.public void setSourceAsList(List list)
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.Copyright © 2004–2016 XStream. All rights reserved.