Package org.restlet.ext.xml
Class Transformer
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.routing.Filter
-
- org.restlet.ext.xml.Transformer
-
- All Implemented Interfaces:
org.restlet.Uniform
public class Transformer extends org.restlet.routing.Filter
Filter that can transform XML representations by applying an XSLT transform sheet. It uses theorg.restlet.representation.TransformRepresentation
to actually transform the XML entities.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.- Author:
- Jerome Louvel
-
-
Field Summary
Fields Modifier and Type Field Description static int
MODE_REQUEST
Mode that transforms request entities before their handling by the attached Restlet.static int
MODE_RESPONSE
Mode that transforms response entities after their handling by the attached Restlet.
-
Constructor Summary
Constructors Constructor Description Transformer(int mode, org.restlet.representation.Representation transformSheet)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterHandle(org.restlet.Request request, org.restlet.Response response)
protected int
beforeHandle(org.restlet.Request request, org.restlet.Response response)
protected boolean
canTransform(org.restlet.representation.Representation representation)
Indicates if the filter can transform the given message entity.int
getMode()
Returns the transformation mode.org.restlet.data.CharacterSet
getResultCharacterSet()
Returns the character set of the result representation.java.util.List<org.restlet.data.Encoding>
getResultEncodings()
Returns the modifiable list of encodings of the result representation.java.util.List<org.restlet.data.Language>
getResultLanguages()
Returns the modifiable list of languages of the result representation.org.restlet.data.MediaType
getResultMediaType()
Returns the media type of the result representation.org.restlet.representation.Representation
getTransformSheet()
Returns the XSLT transform sheet to apply to message entities.void
setMode(int mode)
Sets the transformation mode.void
setResultCharacterSet(org.restlet.data.CharacterSet resultCharacterSet)
Sets the character set of the result representation.void
setResultEncodings(java.util.List<org.restlet.data.Encoding> resultEncodings)
Sets the encodings of the result representation.void
setResultLanguages(java.util.List<org.restlet.data.Language> resultLanguages)
Sets the languages of the result representation.void
setResultMediaType(org.restlet.data.MediaType resultMediaType)
Sets the media type of the result representation.void
setTransformSheet(org.restlet.representation.Representation transformSheet)
Sets the XSLT transform sheet to apply to message entities.org.restlet.representation.Representation
transform(org.restlet.representation.Representation source)
Transforms a source XML representation by applying an XSLT transform sheet to it.-
Methods inherited from class org.restlet.routing.Filter
doHandle, getNext, handle, hasNext, setNext, setNext, start, stop
-
-
-
-
Field Detail
-
MODE_REQUEST
public static final int MODE_REQUEST
Mode that transforms request entities before their handling by the attached Restlet.- See Also:
- Constant Field Values
-
MODE_RESPONSE
public static final int MODE_RESPONSE
Mode that transforms response entities after their handling by the attached Restlet.- See Also:
- Constant Field Values
-
-
Method Detail
-
afterHandle
protected void afterHandle(org.restlet.Request request, org.restlet.Response response)
- Overrides:
afterHandle
in classorg.restlet.routing.Filter
-
beforeHandle
protected int beforeHandle(org.restlet.Request request, org.restlet.Response response)
- Overrides:
beforeHandle
in classorg.restlet.routing.Filter
-
canTransform
protected boolean canTransform(org.restlet.representation.Representation representation)
Indicates if the filter can transform the given message entity. By default, it always returns true.- Parameters:
representation
- The entity representation to test.- Returns:
- True if the transformation can be applied.
-
getMode
public int getMode()
Returns the transformation mode. See MODE_* constants.- Returns:
- The transformation mode.
-
getResultCharacterSet
public org.restlet.data.CharacterSet getResultCharacterSet()
Returns the character set of the result representation. The default value is null.- Returns:
- The character set of the result representation.
-
getResultEncodings
public java.util.List<org.restlet.data.Encoding> getResultEncodings()
Returns the modifiable list of encodings of the result representation.- Returns:
- The encoding of the result representation.
-
getResultLanguages
public java.util.List<org.restlet.data.Language> getResultLanguages()
Returns the modifiable list of languages of the result representation.- Returns:
- The language of the result representation.
-
getResultMediaType
public org.restlet.data.MediaType getResultMediaType()
Returns the media type of the result representation. The default value is MediaType.APPLICATION_XML.- Returns:
- The media type of the result representation.
-
getTransformSheet
public org.restlet.representation.Representation getTransformSheet()
Returns the XSLT transform sheet to apply to message entities.- Returns:
- The XSLT transform sheet to apply to message entities.
-
setMode
public void setMode(int mode)
Sets the transformation mode. See MODE_* constants.- Parameters:
mode
- The transformation mode.
-
setResultCharacterSet
public void setResultCharacterSet(org.restlet.data.CharacterSet resultCharacterSet)
Sets the character set of the result representation.- Parameters:
resultCharacterSet
- The character set of the result representation.
-
setResultEncodings
public void setResultEncodings(java.util.List<org.restlet.data.Encoding> resultEncodings)
Sets the encodings of the result representation.- Parameters:
resultEncodings
- The encodings of the result representation.
-
setResultLanguages
public void setResultLanguages(java.util.List<org.restlet.data.Language> resultLanguages)
Sets the languages of the result representation.- Parameters:
resultLanguages
- The languages of the result representation.
-
setResultMediaType
public void setResultMediaType(org.restlet.data.MediaType resultMediaType)
Sets the media type of the result representation.- Parameters:
resultMediaType
- The media type of the result representation.
-
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.
-
transform
public org.restlet.representation.Representation transform(org.restlet.representation.Representation source)
Transforms a source XML representation by applying an XSLT transform sheet to it.- Parameters:
source
- The source XML representation.- Returns:
- The generated result representation.
-
-