Top Description Constructors Methods
javax.xml.transform

public abstract Class Transformer

extends Object
Class Inheritance
Known Direct Subclasses
com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl
Imports
java.util.Properties

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.

Author
Jeff Suttor
Since
1.4

Constructor Summary

AccessConstructor and Description
protected
Transformer()

Default constructor is protected on purpose.

Method Summary

Modifier and TypeMethod and Description
public abstract void
clearParameters()

Clear all parameters set with setParameter.

public abstract ErrorListener

Returns:

The current error handler, which should never be null.
getErrorListener
()

Get the error event handler in effect for the transformation.

public abstract Properties

Returns:

A copy of the set of output properties in effect for the next transformation.
getOutputProperties
()

Get a copy of the output properties for the transformation.

public abstract String

Returns:

The string value of the output property, or null if no property was found.
getOutputProperty
(String
A non-null String that specifies an output property name, which may be namespace qualified.
name
)

Get an output property that is in effect for the transformer.

public abstract Object

Returns:

A parameter that has been set with setParameter.
getParameter
(String
of Object to get
name
)

Get a parameter that was explicitly set with setParameter.

public abstract URIResolver

Returns:

An object that implements the URIResolver interface, or null.
getURIResolver
()

Get an object that will be used to resolve URIs used in document().

public void
reset()

Reset this Transformer to its original configuration.

public abstract void
setErrorListener(ErrorListener
The new error listener.
listener
)

Set the error event listener in effect for the transformation.

public abstract void
setOutputProperties(Properties
A set of output properties that will be used to override any of the same properties in affect for the transformation.
oformat
)

Set the output properties for the transformation.

public abstract void
setOutputProperty(String
A non-null String that specifies an output property name, which may be namespace qualified.
name
,
String
The non-null string value of the output property.
value
)

Set an output property that will be in effect for the transformation.

public abstract void
setParameter(String
The name of the parameter, which may begin with a namespace URI in curly braces ({}).
name
,
Object
The value object. This can be any valid Java object. It is up to the processor to provide the proper object conversion or to simply pass the object on for use in an extension.
value
)

Add a parameter for the transformation.

public abstract void
setURIResolver(URIResolver
An object that implements the URIResolver interface, or null.
resolver
)

Set an object that will be used to resolve URIs used in document().

public abstract void
transform(Source
The XML input to transform.
xmlSource
,
Result
The Result of transforming the xmlSource.
outputTarget
)

Transform the XML Source to a Result.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Transformerback to summary
protected Transformer()

Default constructor is protected on purpose.

Method Detail

clearParametersback to summary
public abstract void clearParameters()

Clear all parameters set with setParameter.

getErrorListenerback to summary
public abstract ErrorListener getErrorListener()

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

Returns:ErrorListener

The current error handler, which should never be null.

getOutputPropertiesback to summary
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, setOutputProperties, in the stylesheet, or the default properties, while getOutputProperties().get(String key) will only retrieve properties that were explicitly set by setOutputProperty, setOutputProperties, 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 behaviour is not orthogonal with setOutputProperties.

Returns:Properties

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

See Also
javax.xml.transform.OutputKeys, java.util.Properties, XSL Transformations (XSLT) Version 1.0
getOutputPropertyback to summary
public abstract String getOutputProperty(String name) throws IllegalArgumentException

Get an output property that is in effect for the transformer.

If a property has been set using setOutputProperty, that value will be returned. Otherwise, if a property is explicitly specified in the stylesheet, that value will be returned. If the value of the property has been defaulted, that is, if no value has been set explicitly either with setOutputProperty or in the stylesheet, the result may vary depending on implementation and input stylesheet.

Parameters
name:String

A non-null String that specifies an output property name, which may be namespace qualified.

Returns:String

The string value of the output property, or null if no property was found.

Exceptions
IllegalArgumentException:
If the property is not supported.
See Also
javax.xml.transform.OutputKeys
getParameterback to summary
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.

Parameters
name:String

of Object to get

Returns:Object

A parameter that has been set with setParameter.

getURIResolverback to summary
public abstract URIResolver getURIResolver()

Get an object that will be used to resolve URIs used in document().

Returns:URIResolver

An object that implements the URIResolver interface, or null.

resetback to summary
public void reset()

Reset this Transformer to its original configuration.

Transformer is reset to the same state as when it was created with TransformerFactory#newTransformer(), TransformerFactory#newTransformer(Source source) or Templates#newTransformer(). reset() is designed to allow the reuse of existing Transformers thus saving resources associated with the creation of new Transformers.

The reset Transformer is not guaranteed to have the same URIResolver or ErrorListener Objects, e.g. Object#equals(Object obj). It is guaranteed to have a functionally equal URIResolver and ErrorListener.

Exceptions
UnsupportedOperationException:
When implementation does not override this method.
Since
1.5
setErrorListenerback to summary
public abstract void setErrorListener(ErrorListener listener) throws IllegalArgumentException

Set the error event listener in effect for the transformation.

Parameters
listener:ErrorListener

The new error listener.

Exceptions
IllegalArgumentException:
if listener is null.
setOutputPropertiesback to summary
public abstract void setOutputProperties(Properties oformat)

Set the output properties for the transformation. These properties will override properties set in the Templates with xsl:output.

If argument to this function is null, any properties previously set are removed, and the value will revert to the value defined in the templates object.

Pass a qualified property key name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

An IllegalArgumentException is thrown if any of the argument keys are not recognized and are not namespace qualified.
Parameters
oformat:Properties

A set of output properties that will be used to override any of the same properties in affect for the transformation.

Exceptions
IllegalArgumentException:
When keys are not recognized and are not namespace qualified.
See Also
javax.xml.transform.OutputKeys, java.util.Properties
setOutputPropertyback to summary
public abstract void setOutputProperty(String name, String value) throws IllegalArgumentException

Set an output property that will be in effect for the transformation.

Pass a qualified property name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

The Properties object that was passed to setOutputProperties won't be effected by calling this method.

Parameters
name:String

A non-null String that specifies an output property name, which may be namespace qualified.

value:String

The non-null string value of the output property.

Exceptions
IllegalArgumentException:
If the property is not supported, and is not qualified with a namespace.
See Also
javax.xml.transform.OutputKeys
setParameterback to summary
public abstract void setParameter(String name, Object value)

Add a parameter for the transformation.

Pass a qualified name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

Parameters
name:String

The name of the parameter, which may begin with a namespace URI in curly braces ({}).

value:Object

The value object. This can be any valid Java object. It is up to the processor to provide the proper object conversion or to simply pass the object on for use in an extension.

Exceptions
NullPointerException:
If value is null.
setURIResolverback to summary
public abstract void setURIResolver(URIResolver resolver)

Set an object that will be used to resolve URIs used in document().

If the resolver argument is null, the URIResolver value will be cleared and the transformer will no longer have a resolver.

Parameters
resolver:URIResolver

An object that implements the URIResolver interface, or null.

transformback to summary
public abstract void transform(Source xmlSource, Result outputTarget) throws TransformerException

Transform the XML Source to a Result. Specific transformation behavior is determined by the settings of the TransformerFactory in effect when the Transformer was instantiated and any modifications made to the Transformer instance.

An empty Source is represented as an empty document as constructed by javax.xml.parsers.DocumentBuilder#newDocument(). The result of transforming an empty Source depends on the transformation behavior; it is not always an empty Result.

Parameters
xmlSource:Source

The XML input to transform.

outputTarget:Result

The Result of transforming the xmlSource.

Exceptions
TransformerException:
If an unrecoverable error occurs during the course of the transformation.