Package org.xmlunit.transform
Class Transformation
java.lang.Object
org.xmlunit.transform.Transformation
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOutputProperty
(String name, String value) Add a named output property.void
addParameter
(String name, Object value) Add a named parameter.void
Clear all output properties.void
Clear all output parameters.void
Set the error listener for the transformation.void
Set the TraX factory to use.void
Set the source document to transform.void
Set the stylesheet to use.void
Set the resolver to use for document() and xsl:include/importvoid
Perform the transformation.Convenience method that returns the result of the transformation as a Document.Convenience method that returns the result of the transformation as a String.
-
Constructor Details
-
Transformation
public Transformation()Creates an empty transformation. -
Transformation
- Parameters:
s
- the source to transform - must not be null.
-
-
Method Details
-
setSource
Set the source document to transform.- Parameters:
s
- the source to transform - must not be null.
-
setStylesheet
Set the stylesheet to use.- Parameters:
s
- the stylesheet to use - may be null in which case an identity transformation will be performed.
-
addOutputProperty
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
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
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
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
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
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
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
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
-