org.restlet.resource
Class TransformRepresentation

java.lang.Object
  extended by org.restlet.resource.Variant
      extended by org.restlet.resource.Representation
          extended by org.restlet.resource.StreamRepresentation
              extended by org.restlet.resource.OutputRepresentation
                  extended by org.restlet.resource.TransformRepresentation

public class TransformRepresentation
extends OutputRepresentation

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, you need to 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.resource.Representation
UNKNOWN_SIZE
 
Constructor Summary
TransformRepresentation(Context context, Representation source, Representation transformSheet)
          Constructor.
TransformRepresentation(Representation source, Representation transformSheet)
          Default constructor.
TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, Representation transformSheet)
          Constructor.
TransformRepresentation(javax.xml.transform.URIResolver uriResolver, Representation source, javax.xml.transform.Templates templates)
          Constructor.
 
Method Summary
 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 modiable map of JAXP transformer parameters.
 javax.xml.transform.sax.SAXSource getSaxSource()
          Returns the SAX source associated to the source 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.
 Representation getTransformSheet()
          Returns the XSLT transform sheet to apply to the source representation.
 javax.xml.transform.URIResolver getUriResolver()
          Returns the URI resolver.
 javax.xml.transform.URIResolver getURIResolver()
          Deprecated. Use the getUriResolver method instead.
 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 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(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(Representation transformSheet)
          Sets the XSLT transform sheet to apply to message entities.
 void setUriResolver(javax.xml.transform.URIResolver uriResolver)
          Sets the URI resolver.
 void write(java.io.OutputStream outputStream)
          Writes the representation to a byte stream.
 
Methods inherited from class org.restlet.resource.OutputRepresentation
getStream
 
Methods inherited from class org.restlet.resource.StreamRepresentation
getChannel, getReader, write, write
 
Methods inherited from class org.restlet.resource.Representation
checkDigest, checkDigest, computeDigest, createEmpty, exhaust, getAvailableSize, getDigest, getDownloadName, getExpirationDate, getModificationDate, getRange, getSize, getTag, getText, isAvailable, isDownloadable, isTransient, setAvailable, setDigest, setDownloadable, setDownloadName, setExpirationDate, setModificationDate, setRange, setSize, setTag, setTransient
 
Methods inherited from class org.restlet.resource.Variant
getCharacterSet, getEncodings, getIdentifier, getLanguages, getMediaType, setCharacterSet, setEncodings, setIdentifier, setIdentifier, setLanguages, setMediaType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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(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

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

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 modiable 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 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 the getTemplates().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 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.

getURIResolver

@Deprecated
public javax.xml.transform.URIResolver getURIResolver()
Deprecated. Use the getUriResolver method instead.

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 class OutputRepresentation

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.

write

public void write(java.io.OutputStream outputStream)
           throws java.io.IOException
Description copied from class: Representation
Writes the representation to a byte stream. This method is ensured to write the full content for each invocation unless it is a transient representation, in which case an exception is thrown.

Specified by:
write in class Representation
Parameters:
outputStream - The output stream.
Throws:
java.io.IOException


Copyright © 2005-2008 Noelios Technologies.