org.restlet.ext.xml
Class TransformRepresentation

java.lang.Object
  extended by org.restlet.representation.Variant
      extended by org.restlet.representation.RepresentationInfo
          extended by org.restlet.representation.Representation
              extended by org.restlet.representation.CharacterRepresentation
                  extended by org.restlet.representation.WriterRepresentation
                      extended by org.restlet.ext.xml.TransformRepresentation

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 the Transformer filter.

Author:
Jerome Louvel

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
TransformRepresentation(Context context, Representation source, Representation transformSheet)
          Constructor.
TransformRepresentation(Representation source, Representation transformSheet)
          Default constructor.
TransformRepresentation(URIResolver uriResolver, Representation source, Representation transformSheet)
          Constructor.
TransformRepresentation(URIResolver uriResolver, Representation source, Templates templates)
          Constructor.
 
Method Summary
 ErrorListener getErrorListener()
          Returns the transformer's error listener.
 Map<String,String> getOutputProperties()
          Returns the modifiable map of JAXP transformer output properties.
 Map<String,Object> getParameters()
          Returns the modifiable map of JAXP transformer parameters.
 SAXSource getSaxSource()
          Returns the SAX source associated to the source representation.
 Representation getSourceRepresentation()
          Returns the source representation to transform.
 Templates getTemplates()
          Returns the templates to be used and reused.
 Transformer getTransformer()
          Returns a new transformer to be used.
 TransformerHandler getTransformerHandler()
          Returns the SAX transformer handler associated to the transform sheet.
 Representation getTransformSheet()
          Returns the XSLT transform sheet to apply to the source representation.
 URIResolver getUriResolver()
          Returns the URI resolver.
 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(ErrorListener errorListener)
          Sets the transformer's error listener.
 void setOutputProperties(Map<String,String> outputProperties)
          Sets the modifiable map of JAXP transformer output properties.
 void setParameters(Map<String,Object> parameters)
          Sets the JAXP transformer parameters.
 void setSourceRepresentation(Representation source)
          Sets the source representation to transform.
 void setTemplates(Templates templates)
          Sets the templates to be used and reused.
 void setTransformSheet(Representation transformSheet)
          Sets the XSLT transform sheet to apply to message entities.
 void setUriResolver(URIResolver uriResolver)
          Sets the URI resolver.
static SAXSource toSaxSource(Representation representation)
          Wraps a source representation into a SAXSource.
 void transform(Source source, Result result)
          Transforms the given JAXP source into the given result.
 void write(Result result)
          Writes the transformed source into the given JAXP result.
 void write(Writer writer)
          Writes the transformed source into the given output stream.
 
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, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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(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

public TransformRepresentation(URIResolver uriResolver,
                               Representation source,
                               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 SAXSource toSaxSource(Representation representation)
                             throws IOException
Wraps a source representation into a SAXSource. This method can detect other XmlRepresentation instances to use their XmlRepresentation.getSaxSource() method as well as other TransformRepresentation instances to support transformation chaining.

Parameters:
representation - The source representation.
Returns:
The SAX source.
Throws:
IOException

getErrorListener

public 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 Map<String,String> getOutputProperties()
Returns the modifiable map of JAXP transformer output properties.

Returns:
The JAXP transformer output properties.

getParameters

public Map<String,Object> getParameters()
Returns the modifiable map of JAXP transformer parameters.

Returns:
The JAXP transformer parameters.

getSaxSource

public SAXSource getSaxSource()
                       throws IOException
Returns the SAX source associated to the source representation.

Returns:
The SAX source associated to the source representation.
Throws:
IOException

getSourceRepresentation

public Representation getSourceRepresentation()
Returns the source representation to transform.

Returns:
The source representation to transform.

getTemplates

public Templates getTemplates()
                       throws 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:
IOException

getTransformer

public Transformer getTransformer()
                           throws IOException
Returns a new transformer to be used. Creation is based on the getTemplates().newTransformer() method.

Returns:
The new transformer to be used.
Throws:
IOException

getTransformerHandler

public TransformerHandler getTransformerHandler()
                                         throws IOException
Returns the SAX transformer handler associated to the transform sheet.

Returns:
The SAX transformer handler.
Throws:
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 URIResolver getUriResolver()
Returns the URI resolver.

Returns:
The URI resolver.

getXmlFilter

public XMLFilter getXmlFilter()
                       throws IOException
Returns the SAX XML filter applying the transform sheet to its input.

Returns:
The SAX XML filter.
Throws:
IOException

release

public void release()
Releases the source and transform sheet representations, the transformer and the URI resolver.

Overrides:
release in class Representation

setErrorListener

public void setErrorListener(ErrorListener errorListener)
Sets the transformer's error listener.

Parameters:
errorListener - The transformer's error listener.

setOutputProperties

public void setOutputProperties(Map<String,String> outputProperties)
Sets the modifiable map of JAXP transformer output properties.

Parameters:
outputProperties - The JAXP transformer output properties.

setParameters

public void setParameters(Map<String,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(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(URIResolver uriResolver)
Sets the URI resolver.

Parameters:
uriResolver - The URI resolver.

transform

public void transform(Source source,
                      Result result)
               throws IOException
Transforms the given JAXP source into the given result.

Parameters:
source - The JAXP source object.
result - The JAXP result object.
Throws:
IOException

write

public void write(Result result)
           throws IOException
Writes the transformed source into the given JAXP result. The source is retrieved using the getSaxSource() method.

Parameters:
result - The JAXP result object.
Throws:
IOException

write

public void write(Writer writer)
           throws IOException
Writes the transformed source into the given output stream. By default, it leverages the write(Result) method using a StreamResult object.

Specified by:
write in class Representation
Throws:
IOException


Copyright © 2005-2013 Restlet.