Package org.xmlunit.transform
Class Transformation
- java.lang.Object
-
- org.xmlunit.transform.Transformation
-
public final class Transformation extends java.lang.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.
-
-
Field Summary
Fields Modifier and Type Field Description private javax.xml.transform.ErrorListener
errorListener
private javax.xml.transform.TransformerFactory
factory
private java.util.Properties
output
private java.util.Map<java.lang.String,java.lang.Object>
params
private javax.xml.transform.Source
source
private javax.xml.transform.Source
styleSheet
private javax.xml.transform.URIResolver
uriResolver
-
Constructor Summary
Constructors Constructor Description Transformation()
Transformation(javax.xml.transform.Source s)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOutputProperty(java.lang.String name, java.lang.String value)
Add a named output property.void
addParameter(java.lang.String name, java.lang.Object value)
Add a named parameter.void
clearOutputProperties()
Clear all output properties.void
clearParameters()
Clear all output parameters.void
setErrorListener(javax.xml.transform.ErrorListener l)
Set the error listener for the transformation.void
setFactory(javax.xml.transform.TransformerFactory f)
Set the TraX factory to use.void
setSource(javax.xml.transform.Source s)
Set the source document to transform.void
setStylesheet(javax.xml.transform.Source s)
Set the stylesheet to use.void
setURIResolver(javax.xml.transform.URIResolver r)
Set the resolver to use for document() and xsl:include/importvoid
transformTo(javax.xml.transform.Result r)
Perform the transformation.org.w3c.dom.Document
transformToDocument()
Convenience method that returns the result of the transformation as a Document.java.lang.String
transformToString()
Convenience method that returns the result of the transformation as a String.
-
-
-
Field Detail
-
source
private javax.xml.transform.Source source
-
styleSheet
private javax.xml.transform.Source styleSheet
-
factory
private javax.xml.transform.TransformerFactory factory
-
uriResolver
private javax.xml.transform.URIResolver uriResolver
-
errorListener
private javax.xml.transform.ErrorListener errorListener
-
output
private final java.util.Properties output
-
params
private final java.util.Map<java.lang.String,java.lang.Object> params
-
-
Method Detail
-
setSource
public void setSource(javax.xml.transform.Source s)
Set the source document to transform.- Parameters:
s
- the source to transform - must not be null.
-
setStylesheet
public void setStylesheet(javax.xml.transform.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(java.lang.String name, java.lang.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(java.lang.String name, java.lang.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(javax.xml.transform.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(javax.xml.transform.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(javax.xml.transform.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(javax.xml.transform.Result r)
Perform the transformation.- Parameters:
r
- where to send the transformation result - must not be null- Throws:
java.lang.IllegalStateException
- if source is nulljava.lang.IllegalArgumentException
- if result is nullConfigurationException
- if the TraX system isn't configured properlyXMLUnitException
- if the transformation throws an exception
-
transformToString
public java.lang.String transformToString()
Convenience method that returns the result of the transformation as a String.- Throws:
java.lang.IllegalArgumentException
- if source is nullConfigurationException
- if the TraX system isn't configured properlyXMLUnitException
- if the transformation throws an exception
-
transformToDocument
public org.w3c.dom.Document transformToDocument()
Convenience method that returns the result of the transformation as a Document.- Throws:
java.lang.IllegalArgumentException
- if source is nullConfigurationException
- if the TraX system isn't configured properlyXMLUnitException
- if the transformation throws an exception
-
-