Class JDOMSource
- java.lang.Object
-
- javax.xml.transform.sax.SAXSource
-
- org.jdom.transform.JDOMSource
-
- All Implemented Interfaces:
javax.xml.transform.Source
public class JDOMSource extends javax.xml.transform.sax.SAXSourceA holder for an XML Transformation source: a Document, Element, or list of nodes.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); } }- Version:
- $Revision: 1.20 $, $Date: 2007/11/10 05:29:02 $
- Author:
- Laurent Bihanic, Jason Hunter
- See Also:
JDOMResult
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringJDOM_FEATUREIfTransformerFactory.getFeature(java.lang.String)returnstruewhen passed this value as an argument, the Transformer natively supports JDOM.
-
Constructor Summary
Constructors Constructor Description JDOMSource(java.util.List 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, org.xml.sax.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DocumentgetDocument()Returns the source document used by this TrAX source.java.util.ListgetNodes()Returns the source node list used by this TrAX source.org.xml.sax.XMLReadergetXMLReader()Returns the XMLReader to be used for the Source.voidsetDocument(Document source)Sets the source document used by this TrAX source.voidsetInputSource(org.xml.sax.InputSource inputSource)Sets the SAX InputSource to be used for the Source.voidsetNodes(java.util.List source)Sets the source node list used by this TrAX source.voidsetXMLReader(org.xml.sax.XMLReader reader)Set the XMLReader to be used for the Source.
-
-
-
Field Detail
-
JDOM_FEATURE
public static final java.lang.String JDOM_FEATURE
IfTransformerFactory.getFeature(java.lang.String)returnstruewhen passed this value as an argument, the Transformer natively supports JDOM.Note: This implementation does not override the
SAXSource.FEATUREvalue defined by its superclass to be considered as a SAXSource by Transformer implementations not natively supporting JDOM.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JDOMSource
public JDOMSource(Document source)
Creates a JDOM TrAX source wrapping a JDOM document.- Parameters:
source- the JDOM document to use as source for the transformations- Throws:
java.lang.IllegalArgumentException- ifsourceisnull.
-
JDOMSource
public JDOMSource(java.util.List source)
Creates a JDOM TrAX source wrapping a list of JDOM nodes.- Parameters:
source- the JDOM nodes to use as source for the transformations- Throws:
java.lang.IllegalArgumentException- ifsourceisnull.
-
JDOMSource
public JDOMSource(Element source)
Creates a JDOM TrAX source wrapping a JDOM element.- Parameters:
source- the JDOM element to use as source for the transformations- Throws:
java.lang.IllegalArgumentException- ifsourceisnull.
-
JDOMSource
public JDOMSource(Document source, org.xml.sax.EntityResolver resolver)
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:
java.lang.IllegalArgumentException- ifsourceisnull
-
-
Method Detail
-
setDocument
public void setDocument(Document source)
Sets the source document used by this TrAX source.- Parameters:
source- the JDOM document to use as source for the transformations- Throws:
java.lang.IllegalArgumentException- ifsourceisnull.- See Also:
getDocument()
-
getDocument
public Document getDocument()
Returns the source document used by this TrAX source.- Returns:
- the source document used by this TrAX source or
nullif the source is a node list. - See Also:
setDocument(org.jdom.Document)
-
setNodes
public void setNodes(java.util.List source)
Sets the source node list used by this TrAX source.- Parameters:
source- the JDOM nodes to use as source for the transformations- Throws:
java.lang.IllegalArgumentException- ifsourceisnull.- See Also:
getNodes()
-
getNodes
public java.util.List getNodes()
Returns the source node list used by this TrAX source.- Returns:
- the source node list used by this TrAX source or
nullif the source is a JDOM document. - See Also:
setDocument(org.jdom.Document)
-
setInputSource
public void setInputSource(org.xml.sax.InputSource inputSource) throws java.lang.UnsupportedOperationExceptionSets 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:
setInputSourcein classjavax.xml.transform.sax.SAXSource- Parameters:
inputSource- a valid InputSource reference.- Throws:
java.lang.UnsupportedOperationException- always!
-
setXMLReader
public void setXMLReader(org.xml.sax.XMLReader reader) throws java.lang.UnsupportedOperationExceptionSet the XMLReader to be used for the Source.As this implementation only supports JDOM document as data source, this method throws an
UnsupportedOperationExceptionif the provided reader object does not implement the SAXXMLFilterinterface. Otherwise, the JDOM document reader will be attached as parent of the filter chain.- Overrides:
setXMLReaderin classjavax.xml.transform.sax.SAXSource- Parameters:
reader- a valid XMLReader or XMLFilter reference.- Throws:
java.lang.UnsupportedOperationException- ifreaderis not a SAXXMLFilter.- See Also:
getXMLReader()
-
getXMLReader
public org.xml.sax.XMLReader 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:
getXMLReaderin classjavax.xml.transform.sax.SAXSource- Returns:
- an XMLReader reading the XML data from the source JDOM document.
-
-