cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andre Juffer <>
Subject Cocoon3: string-template; collections
Date Tue, 20 Sep 2011 08:14:39 GMT

I am dealing with the following. I created a simple REST resource, like 
(without setters):

public class TestResource {

     public Response getTest(@PathParam("id") String id)
         TestDTO testDTO = this.testFacade.find(id);
         Map<String, Object> map = new HashMap<String, Object>();
         map.put("test", testDTO);
URLResponseBuilder.newInstance("servlet:tribc-tct:/test.json", map).build();

The TestFacade returns a DTO (data transfer object) and this DTO exposes 
a number of getters. The application must be able to return both XML and 
JSON. So, I place the DTO in a map and 'call' the sitemap for generated 
the response (here as JSON):

<map:match pattern="*.json">
   <map:generate type="string-template" src="xml/{map:1}.xml" />
   <map:transform src="xsl/xml2json.xsl" />
   <map:transform type="logasxml"/>
   <map:transform type="log"/>
   <map:serialize type="json" />  <!-- This serializer is my own -->

The test.xml looks like:

     <!-- and more ...->

You can see that the DTO that was stored in the map is used in the 
test.xml to create an XML representation of the DTO. The above works 
fine (see StringTemplate [1]). The XML is subsequently transformed to JSON.

My problem is now how to use string-template when dealing with a 
collection. That is, the TestFacade returns a collection of DTOs 
(Collecton<TestDTO>), for which I need to make an XML (or JSON) 
representation, like:


My question: How to iterate through a collection of objects with 
string-template to create the above, if the collection is stored in a 
map. The StringTemplate pages are not very easy to read and I did not 
really find a clue how to handle this particular problem. In cocoon 2.2 
one could use <jx:forEach ...>, which was extremely convenient. I was 
hoping that there is a simular way with string-template.

Thanks for any help,

Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email:
University of Oulu, Finland  | WWW:
StruBioCat                   | WWW:
NordProt                     | WWW:
Triacle Biocomputing         | WWW:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message