Hi,
I am dealing with the following. I created a simple REST resource, like
(without setters):
@Path("/test")
public class TestResource {
@GET
@Path("/{id}")
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);
return
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 -->
</map:match>
The test.xml looks like:
<test>
<testId>$test.testId$</testId>
<name>$test.name$</name>
<!-- and more ...->
</test>
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:
<tests>
<test>...</test>
<test>...</test>
</tests>
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: andre.juf...@oulu.fi
University of Oulu, Finland | WWW: www.biochem.oulu.fi/Biocomputing/
StruBioCat | WWW: www.strubiocat.oulu.fi
NordProt | WWW: www.nordprot.org
Triacle Biocomputing | WWW: www.triacle-bc.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@cocoon.apache.org
For additional commands, e-mail: users-h...@cocoon.apache.org