Package org.xmlunit.transform
Class Transformation
- java.lang.Object
-
- org.xmlunit.transform.Transformation
-
public final class Transformation extends Object
Provides a convenience layer over TraX.Apart from IllegalArgumentExceptions if you try to pass in null values only the transform methods will ever throw exceptions and these will be XMLUnit's runtime exceptions.
Each invocation of a transform method will use a fresh Transformer instance, the transform methods are thread-safe.
-
-
Constructor Summary
Constructors Constructor Description Transformation()Creates an empty transformation.Transformation(Source s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOutputProperty(String name, String value)Add a named output property.voidaddParameter(String name, Object value)Add a named parameter.voidclearOutputProperties()Clear all output properties.voidclearParameters()Clear all output parameters.voidsetErrorListener(ErrorListener l)Set the error listener for the transformation.voidsetFactory(TransformerFactory f)Set the TraX factory to use.voidsetSource(Source s)Set the source document to transform.voidsetStylesheet(Source s)Set the stylesheet to use.voidsetURIResolver(URIResolver r)Set the resolver to use for document() and xsl:include/importvoidtransformTo(Result r)Perform the transformation.DocumenttransformToDocument()Convenience method that returns the result of the transformation as a Document.StringtransformToString()Convenience method that returns the result of the transformation as a String.
-
-
-
Constructor Detail
-
Transformation
public Transformation()
Creates an empty transformation.
-
Transformation
public Transformation(Source s)
- Parameters:
s- the source to transform - must not be null.
-
-
Method Detail
-
setSource
public void setSource(Source s)
Set the source document to transform.- Parameters:
s- the source to transform - must not be null.
-
setStylesheet
public void setStylesheet(Source s)
Set the stylesheet to use.- Parameters:
s- the stylesheet to use - may be null in which case an identity transformation will be performed.
-
addOutputProperty
public void addOutputProperty(String name, String value)
Add a named output property.- Parameters:
name- name of the property - must not be nullvalue- value of the property - must not be null
-
clearOutputProperties
public void clearOutputProperties()
Clear all output properties.
-
addParameter
public void addParameter(String name, Object value)
Add a named parameter.- Parameters:
name- name of the parameter - must not be nullvalue- value of the parameter - may be null
-
clearParameters
public void clearParameters()
Clear all output parameters.
-
setFactory
public void setFactory(TransformerFactory f)
Set the TraX factory to use.- Parameters:
f- the factory to use - may be null in which case the default factory will be used.
-
setURIResolver
public void setURIResolver(URIResolver r)
Set the resolver to use for document() and xsl:include/importThe resolver will not be attached to the factory.
- Parameters:
r- the resolver - may be null in which case no explicit resolver will be used
-
setErrorListener
public void setErrorListener(ErrorListener l)
Set the error listener for the transformation.The listener will not be attached to the factory.
- Parameters:
l- the listener - may be null in which case no listener will be used
-
transformTo
public void transformTo(Result r)
Perform the transformation.- Parameters:
r- where to send the transformation result - must not be null- Throws:
IllegalStateException- if source is nullIllegalArgumentException- if result is nullConfigurationException- if the TraX system isn't configured properlyXMLUnitException- if the transformation throws an exception
-
transformToString
public String transformToString()
Convenience method that returns the result of the transformation as a String.- Returns:
- transformed document as string
- Throws:
IllegalArgumentException- if source is nullConfigurationException- if the TraX system isn't configured properlyXMLUnitException- if the transformation throws an exception
-
transformToDocument
public Document transformToDocument()
Convenience method that returns the result of the transformation as a Document.- Returns:
- transformed document
- Throws:
IllegalArgumentException- if source is nullConfigurationException- if the TraX system isn't configured properlyXMLUnitException- if the transformation throws an exception
-
-