Class JDOMSource

java.lang.Object
javax.xml.transform.sax.SAXSource
org.jdom2.transform.JDOMSource
All Implemented Interfaces:
Source

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 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 Details

  • Constructor Details

    • 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<? extends Content> 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.
    • JDOMSource

      public JDOMSource(Document source, 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 transformations
      resolver - Entity resolver to use for the source transformation
      Throws:
      IllegalArgumentException - ifsource is null
  • Method Details

    • 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

      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:
    • setNodes

      public void setNodes(List<? extends Content> 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

      public List<? extends Content> 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

      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.

      Overrides:
      setInputSource in class SAXSource
      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.

      Overrides:
      setXMLReader in class SAXSource
      Parameters:
      reader - a valid XMLReader or XMLFilter reference.
      Throws:
      UnsupportedOperationException - if reader is not a SAX XMLFilter.
      See Also:
    • 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.

      Overrides:
      getXMLReader in class SAXSource
      Returns:
      an XMLReader reading the XML data from the source JDOM document.