Package org.restlet.ext.xml
Class TransformRepresentation
- java.lang.Object
-
public class TransformRepresentation extends WriterRepresentation
Representation able to apply an XSLT transformation. The internal JAXP transformer is created when the getTransformer() method is first called. So, if you need to specify a custom URI resolver, do it before actually using the representation for a transformation.
This representation should be viewed as a wrapper representation that applies a transform sheet on a source representation when it is read or written out. Therefore, it isn't intended to be reused on different sources. For this use case, you should instead use theorg.restlet.routing.Transformerfilter.
-
-
Field Summary
Fields Modifier and Type Field Description private javax.xml.transform.ErrorListenererrorListenerThe transformer's error listener.private java.util.Map<java.lang.String,java.lang.String>outputPropertiesThe JAXP transformer output properties.private java.util.Map<java.lang.String,java.lang.Object>parametersThe JAXP transformer parameters.private RepresentationsourceRepresentationThe source representation to transform.private javax.xml.transform.TemplatestemplatesThe template to be used and reused.private RepresentationtransformSheetThe XSLT transform sheet to apply to message entities.private javax.xml.transform.URIResolveruriResolverThe URI resolver.-
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Modifier Constructor Description TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, javax.xml.transform.Templates templates)Constructor.TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, Representation transformSheet)Constructor.privateTransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, Representation transformSheet, javax.xml.transform.Templates templates)Constructor.TransformRepresentation(Context context, Representation source, Representation transformSheet)Constructor.TransformRepresentation(Representation source, Representation transformSheet)Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.xml.transform.ErrorListenergetErrorListener()Returns the transformer's error listener.java.util.Map<java.lang.String,java.lang.String>getOutputProperties()Returns the modifiable map of JAXP transformer output properties.java.util.Map<java.lang.String,java.lang.Object>getParameters()Returns the modifiable map of JAXP transformer parameters.javax.xml.transform.sax.SAXSourcegetSaxSource()Returns the SAX source associated to the source representation.private javax.xml.transform.sax.SAXTransformerFactorygetSaxTransformerFactory()Returns the default SAX transformer factory.RepresentationgetSourceRepresentation()Returns the source representation to transform.javax.xml.transform.TemplatesgetTemplates()Returns the templates to be used and reused.javax.xml.transform.TransformergetTransformer()Returns a new transformer to be used.javax.xml.transform.sax.TransformerHandlergetTransformerHandler()Returns the SAX transformer handler associated to the transform sheet.RepresentationgetTransformSheet()Returns the XSLT transform sheet to apply to the source representation.javax.xml.transform.URIResolvergetUriResolver()Returns the URI resolver.org.xml.sax.XMLFiltergetXmlFilter()Returns the SAX XML filter applying the transform sheet to its input.voidrelease()Releases the source and transform sheet representations, the transformer and the URI resolver.voidsetErrorListener(javax.xml.transform.ErrorListener errorListener)Sets the transformer's error listener.voidsetOutputProperties(java.util.Map<java.lang.String,java.lang.String> outputProperties)Sets the modifiable map of JAXP transformer output properties.voidsetParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)Sets the JAXP transformer parameters.voidsetSourceRepresentation(Representation source)Sets the source representation to transform.voidsetTemplates(javax.xml.transform.Templates templates)Sets the templates to be used and reused.voidsetTransformSheet(Representation transformSheet)Sets the XSLT transform sheet to apply to message entities.voidsetUriResolver(javax.xml.transform.URIResolver uriResolver)Sets the URI resolver.static javax.xml.transform.sax.SAXSourcetoSaxSource(Representation representation)Wraps a source representation into aSAXSource.voidtransform(javax.xml.transform.Source source, javax.xml.transform.Result result)Transforms the given JAXP source into the given result.voidwrite(java.io.Writer writer)Writes the transformed source into the given output stream.voidwrite(javax.xml.transform.Result result)Writes the transformed source into the given JAXP result.-
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader
-
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write, write
-
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
-
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
-
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
-
-
-
-
Field Detail
-
errorListener
private volatile javax.xml.transform.ErrorListener errorListener
The transformer's error listener.
-
outputProperties
private volatile java.util.Map<java.lang.String,java.lang.String> outputProperties
The JAXP transformer output properties.
-
parameters
private volatile java.util.Map<java.lang.String,java.lang.Object> parameters
The JAXP transformer parameters.
-
sourceRepresentation
private volatile Representation sourceRepresentation
The source representation to transform.
-
templates
private volatile javax.xml.transform.Templates templates
The template to be used and reused.
-
transformSheet
private volatile Representation transformSheet
The XSLT transform sheet to apply to message entities.
-
uriResolver
private volatile javax.xml.transform.URIResolver uriResolver
The URI resolver.
-
-
Constructor Detail
-
TransformRepresentation
public TransformRepresentation(Context context, Representation source, Representation transformSheet)
Constructor. Note that a default URI resolver will be created based on the given context.- Parameters:
context- The parent context.source- The source representation to transform.transformSheet- The XSLT transform sheet to apply.
-
TransformRepresentation
public TransformRepresentation(Representation source, Representation transformSheet)
Default constructor.- Parameters:
source- The source representation to transform.transformSheet- The XSLT transform sheet to apply.
-
TransformRepresentation
public TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, Representation transformSheet)Constructor. Note that a default URI resolver will be created based on the given context.- Parameters:
uriResolver- The JAXP URI resolver.source- The source representation to transform.transformSheet- The XSLT transform sheet to apply.
-
TransformRepresentation
private TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, Representation transformSheet, javax.xml.transform.Templates templates)Constructor.- Parameters:
uriResolver- The optional JAXP URI resolver.source- The source representation to transform.templates- The precompiled JAXP template.
-
TransformRepresentation
public TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, javax.xml.transform.Templates templates)Constructor.- Parameters:
uriResolver- The optional JAXP URI resolver.source- The source representation to transform.templates- The precompiled JAXP template.
-
-
Method Detail
-
toSaxSource
public static javax.xml.transform.sax.SAXSource toSaxSource(Representation representation) throws java.io.IOException
Wraps a source representation into aSAXSource. This method can detect otherXmlRepresentationinstances to use theirXmlRepresentation.getSaxSource()method as well as otherTransformRepresentationinstances to support transformation chaining.- Parameters:
representation- The source representation.- Returns:
- The SAX source.
- Throws:
java.io.IOException
-
getErrorListener
public javax.xml.transform.ErrorListener getErrorListener()
Returns the transformer's error listener. Default value is null, leaving the original listener intact.- Returns:
- The transformer's error listener.
-
getOutputProperties
public java.util.Map<java.lang.String,java.lang.String> getOutputProperties()
Returns the modifiable map of JAXP transformer output properties.- Returns:
- The JAXP transformer output properties.
-
getParameters
public java.util.Map<java.lang.String,java.lang.Object> getParameters()
Returns the modifiable map of JAXP transformer parameters.- Returns:
- The JAXP transformer parameters.
-
getSaxSource
public javax.xml.transform.sax.SAXSource getSaxSource() throws java.io.IOExceptionReturns the SAX source associated to the source representation.- Returns:
- The SAX source associated to the source representation.
- Throws:
java.io.IOException
-
getSaxTransformerFactory
private javax.xml.transform.sax.SAXTransformerFactory getSaxTransformerFactory()
Returns the default SAX transformer factory.- Returns:
- The default SAX transformer factory.
-
getSourceRepresentation
public Representation getSourceRepresentation()
Returns the source representation to transform.- Returns:
- The source representation to transform.
-
getTemplates
public javax.xml.transform.Templates getTemplates() throws java.io.IOExceptionReturns the templates to be used and reused. If no one exists, it creates a new one based on the transformSheet representation and on the URI resolver.- Returns:
- The templates to be used and reused.
- Throws:
java.io.IOException
-
getTransformer
public javax.xml.transform.Transformer getTransformer() throws java.io.IOExceptionReturns a new transformer to be used. Creation is based on thegetTemplates().newTransformer() method.- Returns:
- The new transformer to be used.
- Throws:
java.io.IOException
-
getTransformerHandler
public javax.xml.transform.sax.TransformerHandler getTransformerHandler() throws java.io.IOExceptionReturns the SAX transformer handler associated to the transform sheet.- Returns:
- The SAX transformer handler.
- Throws:
java.io.IOException
-
getTransformSheet
public Representation getTransformSheet()
Returns the XSLT transform sheet to apply to the source representation.- Returns:
- The XSLT transform sheet to apply.
-
getUriResolver
public javax.xml.transform.URIResolver getUriResolver()
Returns the URI resolver.- Returns:
- The URI resolver.
-
getXmlFilter
public org.xml.sax.XMLFilter getXmlFilter() throws java.io.IOExceptionReturns the SAX XML filter applying the transform sheet to its input.- Returns:
- The SAX XML filter.
- Throws:
java.io.IOException
-
release
public void release()
Releases the source and transform sheet representations, the transformer and the URI resolver.- Overrides:
releasein classRepresentation
-
setErrorListener
public void setErrorListener(javax.xml.transform.ErrorListener errorListener)
Sets the transformer's error listener.- Parameters:
errorListener- The transformer's error listener.
-
setOutputProperties
public void setOutputProperties(java.util.Map<java.lang.String,java.lang.String> outputProperties)
Sets the modifiable map of JAXP transformer output properties.- Parameters:
outputProperties- The JAXP transformer output properties.
-
setParameters
public void setParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)
Sets the JAXP transformer parameters.- Parameters:
parameters- The JAXP transformer parameters.
-
setSourceRepresentation
public void setSourceRepresentation(Representation source)
Sets the source representation to transform.- Parameters:
source- The source representation to transform.
-
setTemplates
public void setTemplates(javax.xml.transform.Templates templates)
Sets the templates to be used and reused.- Parameters:
templates- The templates to be used and reused.
-
setTransformSheet
public void setTransformSheet(Representation transformSheet)
Sets the XSLT transform sheet to apply to message entities.- Parameters:
transformSheet- The XSLT transform sheet to apply to message entities.
-
setUriResolver
public void setUriResolver(javax.xml.transform.URIResolver uriResolver)
Sets the URI resolver.- Parameters:
uriResolver- The URI resolver.
-
transform
public void transform(javax.xml.transform.Source source, javax.xml.transform.Result result) throws java.io.IOExceptionTransforms the given JAXP source into the given result.- Parameters:
source- The JAXP source object.result- The JAXP result object.- Throws:
java.io.IOException
-
write
public void write(javax.xml.transform.Result result) throws java.io.IOExceptionWrites the transformed source into the given JAXP result. The source is retrieved using thegetSaxSource()method.- Parameters:
result- The JAXP result object.- Throws:
java.io.IOException
-
write
public void write(java.io.Writer writer) throws java.io.IOExceptionWrites the transformed source into the given output stream. By default, it leverages thewrite(Result)method using aStreamResultobject.- Specified by:
writein classRepresentation- Parameters:
writer- The characters writer.- Throws:
java.io.IOException
-
-