Hi,
by the way, you can also define a unique Resource for the main reason
that there is no need to make a distinction based on the format. Both
HTML and XML representations vehicle the same data and represent the
same concept, ie resource.
That is to say :
* Have a single resource
router.attach("/{device}/filelist", FilelistResource.class);
* This resource defines the supported formats, for example in the
constructor:
getVariants().add(new Variant(MediaType.TEXT_XML);
getVariants().add(new Variant(MediaType.TEXT_HTML);
* Then, just implements the method FilelistResource#represent(Variant
variant) where variant is one of the defined variant, and is computed
according to client's preferences.
You can have a look at the tutorial =>
http://www.restlet.org/documentation/1.1/firstResource
And at the tunnel service for several ways to update client's
preferences =>
http://www.restlet.org/documentation/1.1/api/org/restlet/service/TunnelService.html
best regards,
Thierry Boileau
> Hi --
>
> I have a router in my createRoot method which looks like:
> router.attach("/{device}/{format}/filelist",
> FilelistResource.class);
>
> The goal is to either return a file listing in one of many formats depending
> on how {format} is set (html,xml) for right now. In my Resource constructor
> I set the MediaType to either TEXT_XML or TEXT_HTML.
>
> In my represent method I branch based on the type of representation I need to
> return. I select the filelist in an xml format, immediately returning it in
> a DomRepresentation if xml. My trouble is using the transformer to generate
> output using my xslt and xml.
>
> my represent logic looks like this for the html generation:
>
> // get xml doc containing file list to show
> DomRepresentation xmlRepresentation = getFileListXML();
>
> // need to transform to html
> DomRepresentation xsltRepresentation =
> new DomRepresentation(MediaType.TEXT_XML);
>
> // get a factory to build a document
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance();
> factory.setNamespaceAware(true);
>
> // create a new document builder
> DocumentBuilder docBldr =
> factory.newDocumentBuilder();
> Document xsltDoc = xsltRepresentation.getDocument();
>
> //xsltRepresentation.setDocument(xsltDoc);
> // read in the xsl document
> xsltDoc = docBldr.parse("index.xsl");
>
>
> // create a transformer Transformer transformer =
> new Transformer(Transformer.MODE_RESPONSE,
> xsltRepresentation);
> transformer.setResultMediaType(MediaType.TEXT_HTML);
> //DomRepresentation htmlRepresentation =
> return transformer.transform(xmlRepresentation);
>
> ....
> The output error is as follows
> ---------------
> [Fatal Error] :1:55: Premature end of file.
> ERROR: 'Premature end of file.'
> FATAL ERROR: 'Could not compile stylesheet'
>
>
> Thanks for any help.. I've been stuck on this for quite sometime and dug just
> about everywhere to find a way to use the transformer class.
>
> Thanks
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1249166
>
>
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=1262030