Transformer

public abstract class Transformer extends Object

An instance of this abstract class can transform a source tree into a result tree.

An instance of this class can be obtained with the TransformerFactory.newTransformer method. This instance may then be used to process XML from a variety of sources and write the transformation output to a variety of sinks.

An object of this class may not be used in multiple threads running concurrently. Different Transformers may be used concurrently by different threads.

A Transformer may be used multiple times. Parameters and output properties are preserved across transformations.

Protected Constructor Summary

Transformer()
Default constructor is protected on purpose.

Public Method Summary

abstract void
clearParameters()
Clear all parameters set with setParameter.
abstract ErrorListener
getErrorListener()
Get the error event handler in effect for the transformation.
abstract Properties
getOutputProperties()

Get a copy of the output properties for the transformation.

abstract String
getOutputProperty(String name)
Get an output property that is in effect for the transformer.
abstract Object
getParameter(String name)
Get a parameter that was explicitly set with setParameter.
abstract URIResolver
getURIResolver()
Get an object that will be used to resolve URIs used in document().
void
reset()

Reset this Transformer to its original configuration.

abstract void
setErrorListener(ErrorListener listener)
Set the error event listener in effect for the transformation.
abstract void
setOutputProperties(Properties oformat)
Set the output properties for the transformation.
abstract void
setOutputProperty(String name, String value)
Set an output property that will be in effect for the transformation.
abstract void
setParameter(String name, Object value)
Add a parameter for the transformation.
abstract void
setURIResolver(URIResolver resolver)
Set an object that will be used to resolve URIs used in document().
abstract void
transform(Source xmlSource, Result outputTarget)

Transform the XML Source to a Result.

Inherited Method Summary

Protected Constructors

protected Transformer ()

Default constructor is protected on purpose.

Public Methods

public abstract void clearParameters ()

Clear all parameters set with setParameter.

public abstract ErrorListener getErrorListener ()

Get the error event handler in effect for the transformation. Implementations must provide a default error listener.

Returns
  • The current error handler, which should never be null.

public abstract Properties getOutputProperties ()

Get a copy of the output properties for the transformation.

The properties returned should contain properties set by the user, and properties set by the stylesheet, and these properties are "defaulted" by default properties specified by section 16 of the XSL Transformations (XSLT) W3C Recommendation. The properties that were specifically set by the user or the stylesheet should be in the base Properties list, while the XSLT default properties that were not specifically set should be the default Properties list. Thus, getOutputProperties().getProperty(String key) will obtain any property in that was set by setOutputProperty(String, String), setOutputProperties(Properties), in the stylesheet, or the default properties, while getOutputProperties().get(String key) will only retrieve properties that were explicitly set by setOutputProperty(String, String), setOutputProperties(Properties), or in the stylesheet.

Note that mutation of the Properties object returned will not effect the properties that the transformer contains.

If any of the argument keys are not recognized and are not namespace qualified, the property will be ignored and not returned. In other words the behavior is not orthogonal with setOutputProperties.

Returns
  • A copy of the set of output properties in effect for the next transformation.

public abstract String getOutputProperty (String name)

Get an output property that is in effect for the transformer. The property specified may be a property that was set with setOutputProperty, or it may be a property specified in the stylesheet.

Parameters
name A non-null String that specifies an output property name, which may be namespace qualified.
Returns
  • The string value of the output property, or null if no property was found.
Throws
IllegalArgumentException If the property is not supported.
See Also

public abstract Object getParameter (String name)

Get a parameter that was explicitly set with setParameter.

This method does not return a default parameter value, which cannot be determined until the node context is evaluated during the transformation process.