Thierry Boileau <thboileau <at> gmail.com> writes:

> 
> Hello Fraser,
> 
> Here are some explanations about the Transformer filter with a sample code.
> 
>         Application application = new Application(component.getContext()) {
>             @Override
>             public synchronized Restlet createRoot() {
>                 Router router = new Router(getContext());
>                 Representation xsltRepresentation = <your xslt
> transformation as a StringRepresentation, or FileRepresentation,
> etc.>;
>                 Transformer transformer = new
> Transformer(Transformer.MODE_RESPONSE, xsltRepresentation);
>                 transformer.setNext(MyResource.class);
>                 router.attach("/", transformer);
>                 return router;
>             }
>         };
> 
> As a filter, the Transformer filter applies on hierarchy of Restlet or
> on a Resource (specified by the setNext() method). According to its
> mode, (Transformer.MODE_REQUEST, or  Transformer.MODE_RESPONSE), the
> filter applies an XSLT transformation on representations (conveyed by
> the request or by the response). In the sample code provided above,
> all representations returned by MyResource will be transformed with
> the xsltRepresentation. With the MODE_REQUEST, the transformation
> applies on all representation conveyed by the request (a POST request
> for example).
> Having said that,  I'm not sure to understand clearly your problem.
> Could you tell us where do you retrieve your XML representations from
> the eXist database. In the RFQResource#HandleGet method?
> 
> best regards,
> Thierry Boileau
> 
> On Feb 17, 2008 4:12 PM, Fraser Goffin <goffinf <at> googlemail.com> wrote:
> > version : Restlet 1.1
> >
> > Hi,
> >
> > I am pretty new to Restlet, and, although I have been through the tutorial
> > examples and searched this forum, I can't find an answer to my question, so
> > perhaps one of you can help me.
> >
> > I am retrieving XML instances from an eXist database and before I hand 
them to
> > the caller I want to transform the representation.
> >
> > I thought that I would need to use the Transformer (filter), but I can't 
quite
> > figure out how to hook it up or what methods I should call, or how to pass 
it
> > the XML source and stylesheet (I'm a relative Java novice too .
> >
> > To-date I have a working implementation which attaches a class which 
extends
> > Resource for a couple of URL prototypes :-
> >
> > router.attach("/quotestore/rfq/{quoteref}", RFQResource.class);
> > router.attach("/quotestore/rfq", RFQResource.class);
> >
> > and in RFQResource I implement handleGet/handlePost/... etc. This all works
> > fine.
> >
> > So, can anyone provide me with a simple example of how to introduce my
> > transformation into this implementation.
> >
> > Many Thanks
> >
> > Fraser.
> >
> >
> >
> >
> 
> 

Thanks Thierry I will give this a try.

As far as getting the XML from eXist I do this (as you suspected) in the 
RFQResource.handleGet method (at present using a simple HTTP request - later 
on I might try eXist as embedded), something like this :-

  String resourcePath 
= "http://localhost:8081/exist/rest/db/quotestore/rfq/1000123";;

//               Prepare the request
  Request request = new Request(Method.GET, resourcePath);

//               Ask to the HTTP client connector to handle the call
  Client client = new Client(Protocol.HTTP);
  Response response = client.handle(request);

  if (response.getStatus().isSuccess()) {
    // Output the response entity as a DomRepresentation
    domRep = response.getEntityAsDom();
    ...

Thanks

Fraser.


Reply via email to