wt.util.xml.xslt
Class JAXPXSLTransform

java.lang.Object
  extended bywt.util.xml.xslt.AbstractXSLTransform
      extended bywt.util.xml.xslt.JAXPXSLTransform
All Implemented Interfaces:
DOMXMLSource, ReaderXMLSource, SAX2XMLSource, SAXXMLSource, StreamXMLSource, XMLSource, XSLTransform

class JAXPXSLTransform
extends AbstractXSLTransform


Field Summary
private  JAXPXMLSourceFactory factory
           
private  JAXPStylesheet stylesheet
           
 
Constructor Summary
(package private) JAXPXSLTransform(JAXPXMLSourceFactory factory, XMLSource xmlSource, JAXPStylesheet stylesheet, Hashtable inputParameters)
           
(package private) JAXPXSLTransform(JAXPXMLSourceFactory factory, XMLSource xmlSource, JAXPStylesheet stylesheet, Hashtable inputParameters, String baseURI)
           
 
Method Summary
 String getBaseURI()
          The URI describing the location of the XML data, up to, but not including the file part of the URI.
 Hashtable getInputParameters()
          The parameters to pass into the stylesheet during the transform.
 InputStream getInputStream()
          The input stream that can be read to get the XML data in byte form.
 Node getNode()
          The top-most node in the XML data source.
 Reader getReader()
          The reader that can be read to get the XML data in character form.
 Stylesheet getStyleSheet()
          The stylesheet used by the transform.
private  Transformer getTransformer()
          Produce and configure Transformer object
private  TransformerHandler getTransformerHandler()
          Produce and configure TransformerHandler object
 XMLSource getXMLSource()
          The XMLSource used as input to the transform (Warning: modifying the XML source and modifying it [for example reading from an input stream] will likely result in errors in the transformation).
 void outputToStream(OutputStream out)
          Write the results of the transformation to the specified OutputStream.
 void outputToWriter(Writer out)
          Write the results of the transformation to the specified Writer.
 void produceEvents(ContentHandler contentHandler, LexicalHandler lexicalHandler, DTDHandler dtdHandler)
          Note that the DTD handler is not used as JAXP's SAXResult does not allow a DTDHandler to be passed.
 void produceEvents(DocumentHandler listener)
          Produce the SAX events for the XML source data calling the appropriate handler methods on the provided DocumentHandler instance.
 void setInputParameters(Hashtable inputParameters)
          Reset the input parameters to the specified set.
private static void setTransformParameters(Transformer transformer, Hashtable inputParameters)
          Apply given input parameters (which can be null) to given Transformer (which cannot be null)
 void setXMLSource(XMLSource xmlSource)
          Resets the XMLSource to that specified.
private  void transform(Result result)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

private JAXPXMLSourceFactory factory

stylesheet

private JAXPStylesheet stylesheet
Constructor Detail

JAXPXSLTransform

JAXPXSLTransform(JAXPXMLSourceFactory factory,
                 XMLSource xmlSource,
                 JAXPStylesheet stylesheet,
                 Hashtable inputParameters)
           throws SAXException,
                  IOException

JAXPXSLTransform

JAXPXSLTransform(JAXPXMLSourceFactory factory,
                 XMLSource xmlSource,
                 JAXPStylesheet stylesheet,
                 Hashtable inputParameters,
                 String baseURI)
           throws SAXException,
                  IOException
Method Detail

getStyleSheet

public Stylesheet getStyleSheet()
Description copied from interface: XSLTransform
The stylesheet used by the transform.

Supported API: true

Returns:
Stylesheet

produceEvents

public void produceEvents(ContentHandler contentHandler,
                          LexicalHandler lexicalHandler,
                          DTDHandler dtdHandler)
                   throws SAXException
Note that the DTD handler is not used as JAXP's SAXResult does not allow a DTDHandler to be passed. It should be used to make the XSLT id() function work. As it is, the XSLT id() function will not work when XSLT transforms are directly chained. One must wrap the XSLT transform in another XMLSource implementation (which does not implement SAXXMLSource or SAX2XMLSource) in order for the id() function to work in subsequent transforms in the chain.

It is unclear (to me at least) how to improve on this without jumping through some rather ridiculous hoops to use the SAXTransformerFactory class' newFilter() method (which is quite inconsistent with other aspects of JAXP).

Parameters:
contentHandler -
lexicalHandler -
dtdHandler -
Throws:
SAXException

getNode

public Node getNode()
             throws SAXException
Description copied from interface: DOMXMLSource
The top-most node in the XML data source.

Supported API: true

Returns:
Node
Throws:
SAXException

outputToStream

public void outputToStream(OutputStream out)
                    throws SAXException,
                           IOException
Description copied from interface: XSLTransform
Write the results of the transformation to the specified OutputStream. The character encoding will be the default used by the underlying XSL implementation (most likely the platform default encoding, e.g. Windows-Latin-1) and not necessarily UTF-8. To guarantee a particular character encoding, create and OutputStreamWriter with a specific Java character encoding and use the method outputToWriter(...).

Supported API: true

Parameters:
out -
Throws:
SAXException
IOException
See Also:
XSLTransform.outputToWriter(java.io.Writer)

outputToWriter

public void outputToWriter(Writer out)
                    throws SAXException,
                           IOException
Description copied from interface: XSLTransform
Write the results of the transformation to the specified Writer.

Supported API: true

Parameters:
out -
Throws:
IOException
SAXException

transform

private void transform(Result result)
                throws SAXException,
                       IOException
Throws:
SAXException
IOException

getTransformerHandler

private TransformerHandler getTransformerHandler()
                                          throws TransformerException
Produce and configure TransformerHandler object

Throws:
TransformerException

getTransformer

private Transformer getTransformer()
                            throws TransformerException
Produce and configure Transformer object

Throws:
TransformerException

setTransformParameters

private static void setTransformParameters(Transformer transformer,
                                           Hashtable inputParameters)
Apply given input parameters (which can be null) to given Transformer (which cannot be null)


getBaseURI

public String getBaseURI()
Description copied from interface: XMLSource
The URI describing the location of the XML data, up to, but not including the file part of the URI. For example, the base URI for data sourced at http://www.acme.com/documents/Document1.xml would be http://www.acme.com/documents.

Supported API: true

Specified by:
getBaseURI in interface XMLSource
Returns:
String

getXMLSource

public XMLSource getXMLSource()
Description copied from interface: XSLTransform
The XMLSource used as input to the transform (Warning: modifying the XML source and modifying it [for example reading from an input stream] will likely result in errors in the transformation).

Supported API: true

Specified by:
getXMLSource in interface XSLTransform
Returns:
XMLSource

setXMLSource

public void setXMLSource(XMLSource xmlSource)
Description copied from interface: XSLTransform
Resets the XMLSource to that specified. Useful for resetting the source of a transformation chain.

Supported API: true

Specified by:
setXMLSource in interface XSLTransform
Parameters:
xmlSource -

getInputParameters

public Hashtable getInputParameters()
Description copied from interface: XSLTransform
The parameters to pass into the stylesheet during the transform. Note that modifying this hashtable will modify the parameters available to the stylesheet.

Supported API: true

Specified by:
getInputParameters in interface XSLTransform
Returns:
Hashtable

setInputParameters

public void setInputParameters(Hashtable inputParameters)
Description copied from interface: XSLTransform
Reset the input parameters to the specified set.

Supported API: true

Specified by:
setInputParameters in interface XSLTransform
Parameters:
inputParameters -

getInputStream

public InputStream getInputStream()
                           throws IOException
Description copied from interface: StreamXMLSource
The input stream that can be read to get the XML data in byte form.

Supported API: true

Specified by:
getInputStream in interface StreamXMLSource
Returns:
InputStream
Throws:
IOException

getReader

public Reader getReader()
                 throws IOException
Description copied from interface: ReaderXMLSource
The reader that can be read to get the XML data in character form.

Supported API: true

Specified by:
getReader in interface ReaderXMLSource
Returns:
Reader
Throws:
IOException

produceEvents

public void produceEvents(DocumentHandler listener)
                   throws SAXException
Description copied from interface: SAXXMLSource
Produce the SAX events for the XML source data calling the appropriate handler methods on the provided DocumentHandler instance.

Supported API: false

Specified by:
produceEvents in interface SAXXMLSource
Parameters:
listener - The handler that will "receive" the SAX events as method calls.
Throws:
SAXException