The is provides input to a
JAXP TrAX Transformer.
The following example shows how to apply an XSL Transformation to a JDOM document and get the transformation result in the form of a list of JDOM nodes:
public static List transform(Document doc, String stylesheet)
throws JDOMException {
try {
Transformer transformer = TransformerFactory.newInstance()
.newTransformer(new StreamSource(stylesheet));
JDOMSource in = new JDOMSource(doc);
JDOMResult out = new JDOMResult();
transformer.transform(in, out);
return out.getResult();
}
catch (TransformerException e) {
throw new JDOMException("XSLT Transformation failed", e);
}
}
org.jdom2.transform.JDOMResult
| Modifier and Type | Class and Description |
|---|---|
| private static class | JDOMSource.DocumentReader
An implementation of the SAX2 XMLReader interface that presents a SAX view of a JDOM Document. |
| private static class | JDOMSource.JDOMInputSource
A subclass of the SAX InputSource interface that wraps a JDOM Document. |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | JDOM_FEATURE
If |
| private EntityResolver | resolver
Optional entity resolver associated to the source of
this document or |
| private XMLReader | xmlReader
The XMLReader object associated to this source or
|
| Access | Constructor and Description |
|---|---|
| public | JDOMSource(Document
the JDOM document to use as source for the
transformations source)Creates a JDOM TrAX source wrapping a JDOM document. |
| public | JDOMSource(List<? extends Content>
the JDOM nodes to use as source for the
transformations source)Creates a JDOM TrAX source wrapping a list of JDOM nodes. |
| public | JDOMSource(Element
the JDOM element to use as source for the
transformations source)Creates a JDOM TrAX source wrapping a JDOM element. |
| public | JDOMSource(Document
The JDOM Element to use as source for the
transformations source, EntityResolver Entity resolver to use for the source
transformation resolver)Creates a JDOM TrAX source wrapping a JDOM element with an associated EntityResolver to resolve external entities. |
| Modifier and Type | Method and Description |
|---|---|
| private XMLReader | Returns: XMLReader reading the XML data from the source JDOM document with an optional EntityResolverBuild an XMLReader to be used for the source. |
| public Document | Returns: the source document used by this TrAX source ornull if the source is a node list.Returns the source document used by this TrAX source. |
| public List | Returns: the source node list used by this TrAX source ornull if the source is a JDOM document.Returns the source node list used by this TrAX source. |
| public XMLReader | Returns: an XMLReader reading the XML data from the source JDOM document. |
| public void | setDocument(Document
the JDOM document to use as source for the
transformations source)Sets the source document used by this TrAX source. |
| public void | setInputSource(InputSource
a valid InputSource reference. inputSource)
Sets the SAX InputSource to be used for the Source.
|
| public void | |
| public void | setXMLReader(XMLReader
a valid XMLReader or XMLFilter reference. reader)
Set the XMLReader to be used for the Source.
|
| JDOM_FEATURE | back to summary |
|---|---|
| public static final String JDOM_FEATURE If Note This implementation does not override
the | |
| resolver | back to summary |
|---|---|
| private EntityResolver resolver Optional entity resolver associated to the source of
this document or
| |
| xmlReader | back to summary |
|---|---|
| private XMLReader xmlReader The XMLReader object associated to this source or
| |
| JDOMSource | back to summary |
|---|---|
| public JDOMSource(Document source) Creates a JDOM TrAX source wrapping a JDOM document.
| |
| JDOMSource | back to summary |
|---|---|
| public JDOMSource(List<? extends Content> source) Creates a JDOM TrAX source wrapping a list of JDOM nodes.
| |
| JDOMSource | back to summary |
|---|---|
| public JDOMSource(Element source) Creates a JDOM TrAX source wrapping a JDOM element.
| |
| JDOMSource | back to summary |
|---|---|
| public JDOMSource(Document source, EntityResolver resolver) Creates a JDOM TrAX source wrapping a JDOM element with an associated EntityResolver to resolve external entities.
| |
| buildDocumentReader | back to summary |
|---|---|
| private XMLReader buildDocumentReader() Build an XMLReader to be used for the source. This will create a new instance of DocumentReader with an EntityResolver instance if available.
| |
| getDocument | back to summary |
|---|---|
| public Document getDocument() Returns the source document used by this TrAX source.
| |
| getNodes | back to summary |
|---|---|
| public List Returns the source node list used by this TrAX source.
| |
| getXMLReader | back to summary |
|---|---|
| public XMLReader getXMLReader() Overrides javax. Returns the XMLReader to be used for the Source. This implementation returns a specific XMLReader reading the XML data from the source JDOM document. | |
| setDocument | back to summary |
|---|---|
| public void setDocument(Document source) Sets the source document used by this TrAX source.
| |
| setInputSource | back to summary |
|---|---|
| public void setInputSource(InputSource inputSource) throws UnsupportedOperationException Overrides javax. Sets the SAX InputSource to be used for the Source.
As this implementation only supports JDOM document as data
source, this method always throws an
| |
| setNodes | back to summary |
|---|---|
| public void setNodes(List<? extends Content> source) Sets the source node list used by this TrAX source.
| |
| setXMLReader | back to summary |
|---|---|
| public void setXMLReader(XMLReader reader) throws UnsupportedOperationException Overrides javax. Set the XMLReader to be used for the Source.
As this implementation only supports JDOM document as data
source, this method throws an
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | parse(String
the system identifier (URI). systemId)Implements org. |
| public void | parse(InputSource
the input source for the top-level of the
XML document. input)Implements org. |
| DocumentReader | back to summary |
|---|---|
| public DocumentReader() Public default constructor. | |
| parse | back to summary |
|---|---|
| public void parse(String systemId) throws SAXNotSupportedException Implements org. Parses an XML document from a system identifier (URI).
This implementation does not support reading XML data from
system identifiers, only from JDOM documents. Hence,
this method always throws a
| |
| parse | back to summary |
|---|---|
| public void parse(InputSource input) throws SAXException Implements org. Parses an XML document.
The methods accepts only
| |
This class is nested in JDOMSource as it is not intended to be used independently of its friend: DocumentReader.
org.jdom2.Document
| Modifier and Type | Field and Description |
|---|---|
| private Document | docsource
The source as a JDOM document or a list of JDOM nodes. |
| private List | listsource
The source as a JDOM document or a list of JDOM nodes. |
| Access | Constructor and Description |
|---|---|
| public | JDOMInputSource(Document
the source document. document)Builds a InputSource wrapping the specified JDOM Document. |
| public | JDOMInputSource(List<? extends Content>
the source JDOM nodes. nodes)Builds a InputSource wrapping a list of JDOM nodes. |
| Modifier and Type | Method and Description |
|---|---|
| public Reader | Returns: a Reader to a string representation of the source JDOM document.Overrides org. |
| public Document | |
| public List | |
| public Object | |
| public void | setByteStream(InputStream
a byte stream containing
an XML document. byteStream)Overrides org. |
| public void | setCharacterStream(Reader
a character stream containing
an XML document. characterStream)Overrides org. |
| docsource | back to summary |
|---|---|
| private Document docsource The source as a JDOM document or a list of JDOM nodes. | |
| listsource | back to summary |
|---|---|
| private List<? extends Content> listsource The source as a JDOM document or a list of JDOM nodes. | |
| JDOMInputSource | back to summary |
|---|---|
| public JDOMInputSource(Document document) Builds a InputSource wrapping the specified JDOM Document.
| |
| JDOMInputSource | back to summary |
|---|---|
| public JDOMInputSource(List<? extends Content> nodes) Builds a InputSource wrapping a list of JDOM nodes. | |
| getCharacterStream | back to summary |
|---|---|
| public Reader getCharacterStream() Overrides org. Gets the character stream for this input source. Note that this method is only provided to make this InputSource implementation acceptable by any XML parser. As it generates an in-memory string representation of the JDOM document, it is quite inefficient from both speed and memory consumption points of view. | |
| getDocumentSource | back to summary |
|---|---|
| public Document getDocumentSource() | |
| getListSource | back to summary |
|---|---|
| public List | |
| getSource | back to summary |
|---|---|
| public Object getSource() Returns the source.
| |
| setByteStream | back to summary |
|---|---|
| public void setByteStream(InputStream byteStream) throws UnsupportedOperationException Overrides org. Sets the byte stream for this input source.
This implementation always throws an
| |
| setCharacterStream | back to summary |
|---|---|
| public void setCharacterStream(Reader characterStream) throws UnsupportedOperationException Overrides org. Sets the character stream for this input source.
This implementation always throws an
| |