org.jdom.transform
Class JDOMSource

java.lang.Object
  extended byjavax.xml.transform.sax.SAXSource
      extended byorg.jdom.transform.JDOMSource
All Implemented Interfaces:
Source

public class JDOMSource
extends SAXSource

Acts as an holder for JDOM document sources.

This class shall be used to wrap a JDOM Document to provide it as 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 in, String stylesheet)
                                        throws JDOMException {
     try {
       Transformer transformer = TransformerFactory.newInstance()
                             .newTransformer(new StreamSource(stylesheet));

       JDOMResult out = new JDOMResult();
       transformer.transform(new JDOMSource(in), out);
       return out.getResult();
     }
     catch (TransformerException e) {
       throw new JDOMException("XSLT Trandformation failed", e);
     }
   }
 

Version:
$Revision: 1.14 $, $Date: 2003/04/21 06:40:31 $
Author:
Laurent Bihanic, Jason Hunter
See Also:
JDOMResult

Field Summary
static String JDOM_FEATURE
          If TransformerFactory.getFeature(java.lang.String) returns true when passed this value as an argument, the Transformer natively supports JDOM.
 
Fields inherited from class javax.xml.transform.sax.SAXSource
FEATURE
 
Constructor Summary
JDOMSource(Document source)
          Creates a JDOM TRaX source wrapping a JDOM document.
JDOMSource(Element source)
          Creates a JDOM TRaX source wrapping a JDOM element.
JDOMSource(List source)
          Creates a JDOM TRaX source wrapping a list of JDOM nodes.
 
Method Summary
 Document getDocument()
          Returns the source document used by this TRaX source.
 List getNodes()
          Returns the source node list used by this TRaX source.
 XMLReader getXMLReader()
          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 setNodes(List source)
          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, setSystemId, sourceToInputSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDOM_FEATURE

public static final String JDOM_FEATURE
If TransformerFactory.getFeature(java.lang.String) returns true 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:
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:
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

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:
getDocument()

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:
setDocument(org.jdom.Document)

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:
getNodes()

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:
setDocument(org.jdom.Document)

setInputSource

public void setInputSource(InputSource inputSource)
                    throws UnsupportedOperationException
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.

Parameters:
inputSource - a valid InputSource reference.
Throws:
UnsupportedOperationException - always!

setXMLReader

public void setXMLReader(XMLReader reader)
                  throws UnsupportedOperationException
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 SAX 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 XMLFilter.
See Also:
getXMLReader()

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.


Copyright ? 2003 Jason Hunter, Brett McLaughlin. All Rights Reserved.