Package org.restlet.ext.xml
Class TransformRepresentation
- java.lang.Object
-
- org.restlet.representation.Variant
-
- org.restlet.representation.RepresentationInfo
-
- org.restlet.representation.Representation
-
- org.restlet.representation.CharacterRepresentation
-
- org.restlet.representation.WriterRepresentation
-
- org.restlet.ext.xml.TransformRepresentation
-
public class TransformRepresentation extends org.restlet.representation.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.Transformer
filter.- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Constructor Description TransformRepresentation(javax.xml.transform.URIResolver uriResolver, org.restlet.representation.Representation source, javax.xml.transform.Templates templates)
Constructor.TransformRepresentation(javax.xml.transform.URIResolver uriResolver, org.restlet.representation.Representation source, org.restlet.representation.Representation transformSheet)
Constructor.TransformRepresentation(org.restlet.Context context, org.restlet.representation.Representation source, org.restlet.representation.Representation transformSheet)
Constructor.TransformRepresentation(org.restlet.representation.Representation source, org.restlet.representation.Representation transformSheet)
Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description javax.xml.transform.ErrorListener
getErrorListener()
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.SAXSource
getSaxSource()
Returns the SAX source associated to the source representation.org.restlet.representation.Representation
getSourceRepresentation()
Returns the source representation to transform.javax.xml.transform.Templates
getTemplates()
Returns the templates to be used and reused.javax.xml.transform.Transformer
getTransformer()
Returns a new transformer to be used.javax.xml.transform.sax.TransformerHandler
getTransformerHandler()
Returns the SAX transformer handler associated to the transform sheet.org.restlet.representation.Representation
getTransformSheet()
Returns the XSLT transform sheet to apply to the source representation.javax.xml.transform.URIResolver
getUriResolver()
Returns the URI resolver.org.xml.sax.XMLFilter
getXmlFilter()
Returns the SAX XML filter applying the transform sheet to its input.void
release()
Releases the source and transform sheet representations, the transformer and the URI resolver.void
setErrorListener(javax.xml.transform.ErrorListener errorListener)
Sets the transformer's error listener.void
setOutputProperties(java.util.Map<java.lang.String,java.lang.String> outputProperties)
Sets the modifiable map of JAXP transformer output properties.void
setParameters(java.util.Map<java.lang.String,java.lang.Object> parameters)
Sets the JAXP transformer parameters.void
setSourceRepresentation(org.restlet.representation.Representation source)
Sets the source representation to transform.void
setTemplates(javax.xml.transform.Templates templates)
Sets the templates to be used and reused.void
setTransformSheet(org.restlet.representation.Representation transformSheet)
Sets the XSLT transform sheet to apply to message entities.void
setUriResolver(javax.xml.transform.URIResolver uriResolver)
Sets the URI resolver.static javax.xml.transform.sax.SAXSource
toSaxSource(org.restlet.representation.Representation representation)
Wraps a source representation into aSAXSource
.void
transform(javax.xml.transform.Source source, javax.xml.transform.Result result)
Transforms the given JAXP source into the given result.void
write(java.io.Writer writer)
Writes the transformed source into the given output stream.void
write(javax.xml.transform.Result result)
Writes the transformed source into the given JAXP result.-
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
-
-
-
-
Constructor Detail
-
TransformRepresentation
public TransformRepresentation(org.restlet.Context context, org.restlet.representation.Representation source, org.restlet.representation.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(org.restlet.representation.Representation source, org.restlet.representation.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, org.restlet.representation.Representation source, org.restlet.representation.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
public TransformRepresentation(javax.xml.transform.URIResolver uriResolver, org.restlet.representation.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(org.restlet.representation.Representation representation) throws java.io.IOException
Wraps a source representation into aSAXSource
. This method can detect otherXmlRepresentation
instances to use theirXmlRepresentation.getSaxSource()
method as well as otherTransformRepresentation
instances 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.IOException
Returns the SAX source associated to the source representation.- Returns:
- The SAX source associated to the source representation.
- Throws:
java.io.IOException
-
getSourceRepresentation
public org.restlet.representation.Representation getSourceRepresentation()
Returns the source representation to transform.- Returns:
- The source representation to transform.
-
getTemplates
public javax.xml.transform.Templates getTemplates() throws java.io.IOException
Returns 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.IOException
Returns 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.IOException
Returns the SAX transformer handler associated to the transform sheet.- Returns:
- The SAX transformer handler.
- Throws:
java.io.IOException
-
getTransformSheet
public org.restlet.representation.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.IOException
Returns 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:
release
in classorg.restlet.representation.Representation
-
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(org.restlet.representation.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(org.restlet.representation.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.IOException
Transforms 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.IOException
Writes 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.IOException
Writes the transformed source into the given output stream. By default, it leverages thewrite(Result)
method using aStreamResult
object.- Specified by:
write
in classorg.restlet.representation.Representation
- Throws:
java.io.IOException
-
-