Package org.xmlunit.transform
Class Transformation
- java.lang.Object
-
- org.xmlunit.transform.Transformation
-
public final class Transformation extends java.lang.ObjectProvides 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.ErrorListenererrorListenerprivate javax.xml.transform.TransformerFactoryfactoryprivate java.util.Propertiesoutputprivate java.util.Map<java.lang.String,java.lang.Object>paramsprivate javax.xml.transform.Sourcesourceprivate javax.xml.transform.SourcestyleSheetprivate javax.xml.transform.URIResolveruriResolver
-
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 voidaddOutputProperty(java.lang.String name, java.lang.String value)Add a named output property.voidaddParameter(java.lang.String name, java.lang.Object value)Add a named parameter.voidclearOutputProperties()Clear all output properties.voidclearParameters()Clear all output parameters.voidsetErrorListener(javax.xml.transform.ErrorListener l)Set the error listener for the transformation.voidsetFactory(javax.xml.transform.TransformerFactory f)Set the TraX factory to use.voidsetSource(javax.xml.transform.Source s)Set the source document to transform.voidsetStylesheet(javax.xml.transform.Source s)Set the stylesheet to use.voidsetURIResolver(javax.xml.transform.URIResolver r)Set the resolver to use for document() and xsl:include/importvoidtransformTo(javax.xml.transform.Result r)Perform the transformation.org.w3c.dom.DocumenttransformToDocument()Convenience method that returns the result of the transformation as a Document.java.lang.StringtransformToString()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
-
-