org.jdom.transform

Class JDOMSource

public class JDOMSource extends SAXSource

A holder for an XML Transformation source: a Document, Element, or list of nodes.

The is provides input to a {@link javax.xml.transform.Transformer 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.18 $, $Date: 2004/08/31 04:43:48 $

Author: Laurent Bihanic Jason Hunter

See Also:

Field Summary
static StringJDOM_FEATURE
If {@link javax.xml.transform.TransformerFactory#getFeature} returns true when passed this value as an argument, the Transformer natively supports JDOM.
Constructor Summary
JDOMSource(Document source)
Creates a JDOM TrAX source wrapping a JDOM document.
JDOMSource(List source)
Creates a JDOM TrAX source wrapping a list of JDOM nodes.
JDOMSource(Element source)
Creates a JDOM TrAX source wrapping a JDOM element.
Method Summary
DocumentgetDocument()
Returns the source document used by this TrAX source.
ListgetNodes()
Returns the source node list used by this TrAX source.
XMLReadergetXMLReader()
Returns the XMLReader to be used for the Source.
voidsetDocument(Document source)
Sets the source document used by this TrAX source.
voidsetInputSource(InputSource inputSource)
Sets the SAX InputSource to be used for the Source.
voidsetNodes(List source)
Sets the source node list used by this TrAX source.
voidsetXMLReader(XMLReader reader)
Set the XMLReader to be used for the Source.

Field Detail

JDOM_FEATURE

public static final String JDOM_FEATURE
If {@link javax.xml.transform.TransformerFactory#getFeature} returns true when passed this value as an argument, the Transformer natively supports JDOM.

Note: This implementation does not override the {@link SAXSource#FEATURE} value defined by its superclass to be considered as a SAXSource by Transformer implementations not natively supporting JDOM.

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: IllegalArgumentException if source is null.

JDOMSource

public JDOMSource(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: IllegalArgumentException if source is null.

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: IllegalArgumentException if source is null.

Method Detail

getDocument

public Document 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: JDOMSource

getNodes

public List 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: JDOMSource

getXMLReader

public 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.

Returns: an XMLReader reading the XML data from the source JDOM document.

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: IllegalArgumentException if source is null.

See Also: JDOMSource

setInputSource

public void setInputSource(InputSource inputSource)
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 {@link UnsupportedOperationException}.

Parameters: inputSource a valid InputSource reference.

Throws: UnsupportedOperationException always!

setNodes

public void setNodes(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: IllegalArgumentException if source is null.

See Also: JDOMSource

setXMLReader

public void setXMLReader(XMLReader reader)
Set the XMLReader to be used for the Source.

As this implementation only supports JDOM document as data source, this method throws an {@link UnsupportedOperationException} if the provided reader object does not implement the SAX {@link XMLFilter} interface. Otherwise, the JDOM document reader will be attached as parent of the filter chain.

Parameters: reader a valid XMLReader or XMLFilter reference.

Throws: UnsupportedOperationException if reader is not a SAX {@link XMLFilter}.

See Also: JDOMSource

Copyright B) 2004 Jason Hunter, Brett McLaughlin. All Rights Reserved.