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 Details

    • Transformation

      public Transformation()
      Creates an empty transformation.
    • Transformation

      public Transformation(Source s)
      Parameters:
      s - the source to transform - must not be null.
  • Method Details

    • 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 null
      value - 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 null
      value - 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/import

      The 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 null
      IllegalArgumentException - if result is null
      ConfigurationException - if the TraX system isn't configured properly
      XMLUnitException - 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 null
      ConfigurationException - if the TraX system isn't configured properly
      XMLUnitException - 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 null
      ConfigurationException - if the TraX system isn't configured properly
      XMLUnitException - if the transformation throws an exception