Class JDOMSource
- All Implemented Interfaces:
Source
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);
}
}
- Author:
- Laurent Bihanic, Jason Hunter
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
IfTransformerFactory.getFeature(java.lang.String)
returnstrue
when passed this value as an argument, the Transformer natively supports JDOM. -
Constructor Summary
ConstructorsConstructorDescriptionJDOMSource
(List<? extends Content> source) Creates a JDOM TrAX source wrapping a list of JDOM nodes.JDOMSource
(Document source) Creates a JDOM TrAX source wrapping a JDOM document.JDOMSource
(Document source, EntityResolver resolver) Creates a JDOM TrAX source wrapping a JDOM element with an associated EntityResolver to resolve external entities.JDOMSource
(Element source) Creates a JDOM TrAX source wrapping a JDOM element. -
Method Summary
Modifier and TypeMethodDescriptionReturns the source document used by this TrAX source.getNodes()
Returns the source node list used by this TrAX source.Returns the XMLReader to be used for the Source.void
setDocument
(Document source) Sets the source document used by this TrAX source.void
setInputSource
(InputSource inputSource) Sets the SAX InputSource to be used for the Source.void
Sets the source node list used by this TrAX source.void
setXMLReader
(XMLReader reader) Set the XMLReader to be used for the Source.Methods inherited from class javax.xml.transform.sax.SAXSource
getInputSource, getSystemId, isEmpty, setSystemId, sourceToInputSource
-
Field Details
-
JDOM_FEATURE
IfTransformerFactory.getFeature(java.lang.String)
returnstrue
when passed this value as an argument, the Transformer natively supports JDOM.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 JDOM.- See Also:
-
-
Constructor Details
-
JDOMSource
Creates a JDOM TrAX source wrapping a JDOM document.- Parameters:
source
- the JDOM document to use as source for the transformations- Throws:
IllegalArgumentException
- ifsource
isnull
.
-
JDOMSource
Creates a JDOM TrAX source wrapping a list of JDOM nodes.- Parameters:
source
- the JDOM nodes to use as source for the transformations- Throws:
IllegalArgumentException
- ifsource
isnull
.
-
JDOMSource
Creates a JDOM TrAX source wrapping a JDOM element.- Parameters:
source
- the JDOM element to use as source for the transformations- Throws:
IllegalArgumentException
- ifsource
isnull
.
-
JDOMSource
Creates a JDOM TrAX source wrapping a JDOM element with an associated EntityResolver to resolve external entities.- Parameters:
source
- The JDOM Element to use as source for the transformationsresolver
- Entity resolver to use for the source transformation- Throws:
IllegalArgumentException
- ifsource
isnull
-
-
Method Details
-
setDocument
Sets the source document used by this TrAX source.- Parameters:
source
- the JDOM document to use as source for the transformations- Throws:
IllegalArgumentException
- ifsource
isnull
.- See Also:
-
getDocument
Returns the source document used by this TrAX source.- Returns:
- the source document used by this TrAX source or
null
if the source is a node list. - See Also:
-
setNodes
Sets the source node list used by this TrAX source.- Parameters:
source
- the JDOM nodes to use as source for the transformations- Throws:
IllegalArgumentException
- ifsource
isnull
.- See Also:
-
getNodes
Returns the source node list used by this TrAX source.- Returns:
- the source node list used by this TrAX source or
null
if the source is a JDOM document. - See Also:
-
setInputSource
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
UnsupportedOperationException
.- Overrides:
setInputSource
in classSAXSource
- Parameters:
inputSource
- a valid InputSource reference.- Throws:
UnsupportedOperationException
- always!
-
setXMLReader
Set the XMLReader to be used for the Source.As this implementation only supports JDOM document as data source, this method throws an
UnsupportedOperationException
if the provided reader object does not implement the SAXXMLFilter
interface. Otherwise, the JDOM document reader will be attached as parent of the filter chain.- Overrides:
setXMLReader
in classSAXSource
- Parameters:
reader
- a valid XMLReader or XMLFilter reference.- Throws:
UnsupportedOperationException
- ifreader
is not a SAXXMLFilter
.- See Also:
-
getXMLReader
Returns the XMLReader to be used for the Source.This implementation returns a specific XMLReader reading the XML data from the source JDOM document.
- Overrides:
getXMLReader
in classSAXSource
- Returns:
- an XMLReader reading the XML data from the source JDOM document.
-