Package org.custommonkey.xmlunit
Class Transform
- java.lang.Object
-
- org.custommonkey.xmlunit.Transform
-
public class Transform extends java.lang.Object
Handy wrapper for an XSLT transformation performed using JAXP/Trax. Note that transformation is not actually performed until a call togetResultXXX
method, and Templates are not used.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
Transform.Trans<R>
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.Object>
parameters
private static java.io.File
PWD
private Transformation
transformation
-
Constructor Summary
Constructors Modifier Constructor Description Transform(java.lang.String input, java.io.File stylesheet)
Create a transformation using String input XML and stylesheet in a FileTransform(java.lang.String input, java.lang.String stylesheet)
Create a transformation using String input XML and String stylesheetTransform(javax.xml.transform.Source inputSource, javax.xml.transform.Source stylesheetSource)
Create a transformation using Source input XML and Source stylesheetTransform(org.w3c.dom.Node sourceNode)
Create a transformation that allows us to serialize a DOM NodeTransform(org.w3c.dom.Node sourceNode, java.io.File stylesheet)
Create a transformation from an input Node and stylesheet in a FileTransform(org.w3c.dom.Node sourceNode, java.lang.String stylesheet)
Create a transformation from an input Node and stylesheet in a StringTransform(org.xml.sax.InputSource input, java.io.File stylesheet)
Create a transformation using InputSource input XML and stylesheet in a FileTransform(org.xml.sax.InputSource input, org.xml.sax.InputSource stylesheet)
Create a transformation using InputSource input XML and InputSource stylesheetprivate
Transform(Input.Builder input, Input.Builder stylesheet)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearParameters()
Clear parameters used for the transformationprivate java.lang.String
getDefaultSystemId()
java.lang.Object
getParameter(java.lang.String name)
See a parameter used for the transformationorg.w3c.dom.Document
getResultDocument()
Perform the XSLT transformation specified in the constructorjava.lang.String
getResultString()
Perform the XSLT transformation specified in the constructorprivate void
provideSystemIdIfRequired(javax.xml.transform.Source source)
Ensure that the source has a systemIdvoid
setErrorListener(javax.xml.transform.ErrorListener errorListener)
Set the ErrorListener for the transformationvoid
setOutputProperties(java.util.Properties outputProperties)
Override output properties specified in the transformation stylesheetvoid
setOutputProperty(java.lang.String name, java.lang.String value)
Override an output property specified in the transformation stylesheetvoid
setParameter(java.lang.String name, java.lang.Object value)
Add a parameter for the transformationvoid
setURIResolver(javax.xml.transform.URIResolver uriResolver)
Set the URIResolver for the transformationprotected void
transformTo(javax.xml.transform.Result result)
Perform the actual transformation(package private) static <R> R
withExceptionHandling(Transform.Trans<R> trans)
-
-
-
Field Detail
-
PWD
private static final java.io.File PWD
-
transformation
private final Transformation transformation
-
parameters
private final java.util.Map<java.lang.String,java.lang.Object> parameters
-
-
Constructor Detail
-
Transform
public Transform(java.lang.String input, java.lang.String stylesheet)
Create a transformation using String input XML and String stylesheet- Parameters:
input
-stylesheet
-
-
Transform
public Transform(java.lang.String input, java.io.File stylesheet)
Create a transformation using String input XML and stylesheet in a File- Parameters:
input
-stylesheet
-
-
Transform
public Transform(org.xml.sax.InputSource input, org.xml.sax.InputSource stylesheet)
Create a transformation using InputSource input XML and InputSource stylesheet- Parameters:
input
-stylesheet
-
-
Transform
public Transform(org.xml.sax.InputSource input, java.io.File stylesheet)
Create a transformation using InputSource input XML and stylesheet in a File- Parameters:
input
-stylesheet
-
-
Transform
public Transform(org.w3c.dom.Node sourceNode)
Create a transformation that allows us to serialize a DOM Node- Parameters:
sourceNode
-
-
Transform
public Transform(org.w3c.dom.Node sourceNode, java.lang.String stylesheet)
Create a transformation from an input Node and stylesheet in a String- Parameters:
sourceNode
-stylesheet
-
-
Transform
public Transform(org.w3c.dom.Node sourceNode, java.io.File stylesheet)
Create a transformation from an input Node and stylesheet in a File- Parameters:
sourceNode
-stylesheet
-
-
Transform
private Transform(Input.Builder input, Input.Builder stylesheet)
-
Transform
public Transform(javax.xml.transform.Source inputSource, javax.xml.transform.Source stylesheetSource)
Create a transformation using Source input XML and Source stylesheet- Parameters:
inputSource
-stylesheetSource
-
-
-
Method Detail
-
provideSystemIdIfRequired
private void provideSystemIdIfRequired(javax.xml.transform.Source source)
Ensure that the source has a systemId- Parameters:
source
-
-
getDefaultSystemId
private java.lang.String getDefaultSystemId()
- Returns:
- the current working directory as an URL-form string
-
transformTo
protected void transformTo(javax.xml.transform.Result result) throws javax.xml.transform.TransformerException
Perform the actual transformation- Parameters:
result
-- Throws:
javax.xml.transform.TransformerException
-
getResultString
public java.lang.String getResultString() throws javax.xml.transform.TransformerException
Perform the XSLT transformation specified in the constructor- Returns:
- the result as a String
- Throws:
javax.xml.transform.TransformerException
-
getResultDocument
public org.w3c.dom.Document getResultDocument() throws javax.xml.transform.TransformerException
Perform the XSLT transformation specified in the constructor- Returns:
- the result as a DOM Document
- Throws:
javax.xml.transform.TransformerException
-
setOutputProperty
public void setOutputProperty(java.lang.String name, java.lang.String value)
Override an output property specified in the transformation stylesheet- Parameters:
name
-value
-
-
setOutputProperties
public void setOutputProperties(java.util.Properties outputProperties)
Override output properties specified in the transformation stylesheet- Parameters:
outputProperties
-- See Also:
Transformer.setOutputProperties(java.util.Properties)
-
setParameter
public void setParameter(java.lang.String name, java.lang.Object value)
Add a parameter for the transformation- Parameters:
name
-value
-- See Also:
Transformer.setParameter(java.lang.String, java.lang.Object)
-
getParameter
public java.lang.Object getParameter(java.lang.String name)
See a parameter used for the transformation- Parameters:
name
-- Returns:
- the parameter value
- See Also:
Transformer.getParameter(java.lang.String)
-
clearParameters
public void clearParameters()
Clear parameters used for the transformation- See Also:
Transformer.clearParameters()
-
setURIResolver
public void setURIResolver(javax.xml.transform.URIResolver uriResolver)
Set the URIResolver for the transformation- See Also:
Transformer.setURIResolver(javax.xml.transform.URIResolver)
-
setErrorListener
public void setErrorListener(javax.xml.transform.ErrorListener errorListener)
Set the ErrorListener for the transformation- See Also:
Transformer.setErrorListener(javax.xml.transform.ErrorListener)
-
withExceptionHandling
static <R> R withExceptionHandling(Transform.Trans<R> trans) throws javax.xml.transform.TransformerException
- Throws:
javax.xml.transform.TransformerException
-
-